小编Eri*_*ler的帖子

剧作家无法在 Ubuntu 上打开浏览器

我试图弄清楚如何打开一个有头浏览器来从在 Docker 容器中运行的 NestJs 应用程序内部执行一些任务。

\n

申请代码:

\n
import { Controller, Get } from '@nestjs/common';\nimport { AppService } from './app.service';\nimport { chromium } from "playwright";\n\n@Controller()\nexport class AppController {\n  constructor(private readonly appService: AppService) {}\n\n  @Get()\n  async getHello(): Promise<string> {\n    const browser = await chromium.launch({ \n      headless: false,\n      env: {\n        "DISPLAY": ":99"\n      }\n    });\n    const context = await browser.newContext({ javaScriptEnabled: true });\n    const page = await context.newPage();\n\n    await page.goto("http://www.google.com");\n    await page.waitForLoadState("load");\n\n    return "Yay";\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Dockerfile:

\n
FROM ubuntu:20.04 AS BUILD_IMAGE\n\n# INSTALL …
Run Code Online (Sandbox Code Playgroud)

linux x11 xserver docker playwright

5
推荐指数
0
解决办法
3933
查看次数

标签 统计

docker ×1

linux ×1

playwright ×1

x11 ×1

xserver ×1