koishijs/koishi-plugin-puppeteer

Bug: puppeteer未正常运行

vlssu opened this issue · 29 comments

vlssu commented

Describe the bug

比如插件商店里面的下棋的插件chess 按理说棋盘是以图片的形式发出来的,但实际上发的字符

Steps to reproduce

直接在插件里面安装puppeteer,并不做任何配置直接启用插件

Expected behavior

下棋的插件chess 应该是正确的发送图片(在使用v3koishi时成功过,但后来也忘记怎么操作了,但确实要自己手动的安装chrome的一个模块,
或许可以在写这个插件的是否自动检测,没有的进行安装一个?

在自定义那边,设置了指定文件也失败了
https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/982053/chrome-linux.zip

2022-04-27 13:02:14 [W] ndefined;1mapp Error: Failed to launch the browser process!
                        [0427/130214.085519:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/main/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
                        #0 0x5564dbb87b89 base::debug::CollectStackTrace()
                        koishijs/koishi#1 0x5564dbaec433 base::debug::StackTrace::StackTrace()
                        koishijs/koishi#2 0x5564dbaff330 logging::LogMessage::~LogMessage()
                        koishijs/koishi#3 0x5564d9ae499b content::ZygoteHostImpl::Init()
                        koishijs/koishi#4 0x5564db695372 content::ContentMainRunnerImpl::Initialize()
                        koishijs/koishi#5 0x5564db693439 content::RunContentProcess()
                        koishijs/koishi#6 0x5564db69358e content::ContentMain()
                        koishijs/koishi#7 0x5564db6eed7a headless::(anonymous namespace)::RunContentMain()
                        koishijs/koishi#8 0x5564db6eea85 headless::HeadlessShellMain()
                        koishijs/koishi#9 0x5564d81523e8 ChromeMain
                        koishijs/koishi#10 0x7ff612bb8555 __libc_start_main
                        koishijs/koishi#11 0x5564d815222a _start
                        
                        
                        
                        TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
                        
                            at onClose (/koishi地址/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
                            at Interface.<anonymous> (/koishi地址/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:231:68)
                            at Interface.emit (events.js:412:35)
                            at Interface.close (readline.js:530:8)
                            at Socket.onend (readline.js:254:10)
                            at Socket.emit (events.js:412:35)
                            at endReadableNT (internal/streams/readable.js:1334:12)
                            at processTicksAndRejections (internal/process/task_queues.js:82:21)

Screenshots

2022-04-27 12:51:21 [W] ndefined;1mapp TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r982053 is guaranteed to work.
                            at Timeout.onTimeout (/koishi地址/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:252:20)
                            at listOnTimeout (internal/timers.js:557:17)
                            at processTimers (internal/timers.js:500:7)

image

Versions

  • OS: CentOS 7.9.2009 x86_64
  • Platform: onebot
  • Node version: v14.19.0
  • Koishi version: 4.6.1

Additional context

No response

It says you can try the --no-sandbox option. Have you tried?

vlssu commented

It says you can try the --no-sandbox option. Have you tried?

Tried it, still getting an error.

2022-04-27 18:00:58 [W] ndefined;1mapp Error: Failed to launch the browser process! spawn /chrome-linux/chrome --no-sandbox ENOENT
                        
                        
                        TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
                        
                            at onClose (/koishi4地址/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
                            at ChildProcess.<anonymous> (/koishi4地址/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:233:85)
                            at ChildProcess.emit (events.js:400:28)
                            at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
                            at onErrorNT (internal/child_process.js:469:16)
                            at processTicksAndRejections (internal/process/task_queues.js:82:21)

提供一下环境信息,包括系统版本,Node 版本和 chromium 版本。

try not to specify the path of chrome executable, just add the option.

Also, check if there is an instance of chromium under node_modules/puppeteer/bin

vlssu commented

try not to specify the path of chrome executable, just add the option.

Also, check if there is an instance of chromium under node_modules/puppeteer/bin

The error I sent before was not specified, but he still reported an error.

vlssu commented

提供一下环境信息,包括系统版本,Node 版本和 chromium 版本。

OS: CentOS 7.9.2009 x86_64
Platform: onebot
Node version: v14.19.0
Koishi version: 4.6.1
chromium: 982053
https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/982053/chrome-linux.zip

try not to specify the path of chrome executable, just add the option.

Also, check if there is an instance of chromium under node_modules/puppeteer/bin

The error I sent before was not specified, but he still reported an error.

But the first error indicated you have incoked chrome successfully, just failed to enter the sandbox mode, so --no-sandbox is a potential solution here.

vlssu commented

try not to specify the path of chrome executable, just add the option.
Also, check if there is an instance of chromium under node_modules/puppeteer/bin

The error I sent before was not specified, but he still reported an error.

But the first error indicated you have incoked chrome successfully, just failed to enter the sandbox mode, so --no-sandbox is a potential solution here.

In the error message I see this Running as root without --no-sandbox is not supported., but not using root will cause the plugin to fail to install in the control panel.

In the error message I see this Running as root without --no-sandbox is not supported., but not using root will cause the plugin to fail to install in the control panel.

That is because you have some permission issue in your current workspace, for example, the folder is created by root and not allow other users to modify files inside it.
Theoretically you should run koishi as non-root user, so you might need to chown and chmod your workspace folders.

vlssu commented

In the error message I see this Running as root without --no-sandbox is not supported., but not using root will cause the plugin to fail to install in the control panel.

That is because you have some permission issue in your current workspace, for example, the folder is created by root and not allow other users to modify files inside it. Theoretically you should run koishi as non-root user, so you might need to chown and chmod your workspace folders.

image
I've done it again now, and he didn't report an error, but it still didn't work properly.

I think the chess plugin would output text until you type chess --imageMode lol.

vlssu commented

I think the chess plugin would output text until you type chess --imageMode lol.

image
Is that so? It doesn't seem to work, but I'm fine in koishi3 version.

Ah, it's so uncomfortable. Although I don't use this function for a long time, it is the easiest one I know to check whether it is working properly.

You sure you type the command right? What I see in the image seems like you used a full-width dash (——) instead of half-width hyphens (-).

should be --image-mode

should be --image-mode

Options always are kebab-case même even registered as camelCase in code?

I've beening always writting like this, the command above might work but I'm not sure.

vlssu commented

C6QGKDYMBUQD19P(}M52P$C
黑白棋 --image-mode
May be caused by the font, it looks like (——)

黑白棋 --image-mode

Is your "黒白棋" a shortcut or an alias? If it is a shortcut, you should register it with prefix and fuzzy, otherwise it would just ignore your arguments.

ctx
  .command("chess")
  .shortcut("黒白棋", { prefix: true, fuzzy: true })
  //                         ^   like this.   ^
vlssu commented

黑白棋 --image-mode

Is your "黒白棋" a shortcut or an alias? If it is a shortcut, you should register it with prefix and fuzzy, otherwise it would just ignore your arguments.

ctx
  .command("chess")
  .shortcut("黒白棋", { prefix: true, fuzzy: true })
  //                         ^   like this.   ^

"黒白棋" is a chessboard in chess. Direct input of chess --image-mode will not generate a chessboard

https://github.com/koishijs/koishi-plugin-chess/blob/cca17d3f455b02b343e3ef06c753c3bafe5c1a90/src/index.ts#L56

Ah, I see.
So it is a shortcut, I think you should call the chess command instead.

Direct input of chess --image-mode will not generate a chessboard

This is not a command for playing, but for setting the "mode" to the image mode.
Koishi would reply something like "已切换到图片模式。" if you successfully setup puppeteer and chess plugin when you enter this command. If koishi replies something else, that means your puppeteer isn't initialised correctly. You should check out if there is a log that says "app apply plugin puppeteer" without error.

By the way, what is the output if you type "help chess", does it says that there are options "--image-mode" and "--text-mode" in the reply?

vlssu commented

https://github.com/koishijs/koishi-plugin-chess/blob/cca17d3f455b02b343e3ef06c753c3bafe5c1a90/src/index.ts#L56

Ah, I see. So it is a shortcut, I think you should call the chess command instead.

Direct input of chess --image-mode will not generate a chessboard

This is not a command for playing, but for setting the "mode" to the image mode. Koishi would reply something like "已切换到图片模式。" if you successfully setup puppeteer and chess plugin when you enter this command. If koishi replies something else, that means your puppeteer isn't initialised correctly. You should check out if there is a log that says "app apply plugin puppeteer" without error.

By the way, what is the output if you type "help chess", does it says that there are options "--image-mode" and "--text-mode" in the reply?

2022-04-28 10:37:46 [W] ndefined;1mmarket Error: read ECONNRESET
                            at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)
2022-04-28 10:37:58 [W] ndefined;1mapp TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r982053 is guaranteed to work.
                            at Timeout.onTimeout (/koishi4/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:252:20)
                            at listOnTimeout (internal/timers.js:557:17)
                            at processTimers (internal/timers.js:500:7)
2022-04-28 10:38:13 [D] ndefined;1mmessage [#] Frank: chess --image-mode

I just saw that there was indeed an error, but it was only displayed when I first entered chess --image-mode.

chess [position]
棋类游戏
输入“五子棋”“黑白棋”“围棋”开始对应的一局游戏。
再输入“落子 A1”将棋子落于 A1 点上。
目前默认使用图片模式。文本模式速度更快,但是在部分机型上可能无法正常显示,同时无法适应过大的棋盘。
可用的选项有:
    --rule <rule>  设置规则,支持的规则有 go, gomoku, othello
    --size <size>  设置大小
    --skip  跳过回合
    --repent  悔棋
    -v, --show, --view  显示棋盘
    -e, --stop, --end  停止游戏
2022-04-28 10:37:58 [W] ndefined;1mapp TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r982053 is guaranteed to work.
                            at Timeout.onTimeout (/koishi4/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:252:20)
                            at listOnTimeout (internal/timers.js:557:17)
                            at processTimers (internal/timers.js:500:7)

So now what is the situation? You choose the chrome that you downloaded or the one bundled in puppeteer?

What I saw is that puppeteer didn't successfully connect to chrome.

vlssu commented

So now what is the situation? You choose the chrome that you downloaded or the one bundled in puppeteer?

What I saw is that puppeteer didn't successfully connect to chrome.

What I posted just now was bundled with puppeteer, and now this is my own.

2022-04-28 10:45:14 [I] ndefined;1mapp reload plugin ndefinedmpuppeteer
2022-04-28 10:45:14 [W] ndefined;1mapp Error: Failed to launch the browser process! spawn /www/chrome-linux/chrome --no-sandbox ENOENT
                        
                        
                        TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
                        
                            at onClose (/koishi4/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
                            at ChildProcess.<anonymous> (/koishi4/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:233:85)
                            at ChildProcess.emit (events.js:400:28)
                            at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
                            at onErrorNT (internal/child_process.js:469:16)
                            at processTicksAndRejections (internal/process/task_queues.js:82:21)

Looks like that is a common issue on CentOS 7, what I using is Ubuntu and Debian so I have no many painful experiences while installing the puppeteer.

Try check out:
puppeteer/puppeteer#560

puppeteer/puppeteer#2857

vlssu commented

docker中运行依旧会出现这个问题。

docker中运行依旧会出现这个问题。

what do you mean by "这个问题" ?

Also, just FYI, it would be better to install google-chrome-stable via package manager like apt in docker container before starting puppeteer with option path point to the path of the chrome that you installed. De plus, the environment variables PUPPETEER_SKIP_CHROMIUM_DOWNLOAD should be set to true while installing puppeteer to prevent downloading the chromium built-in.

EDIT: There are official trouble shooting steps on their website, try to see yourself here.
Au fait, it is not recommanded to run alpine image with puppeteer, which is trouble-ish many times.
https://pptr.dev/troubleshooting/#running-puppeteer-in-docker

@vissu Are you using the puppeteer-specific docker image? You may try that one.

测试了一下,使用 koishi 官方的 latest-puppeteer docker 镜像并安装 puppeteer 插件及 chess 插件是可以正常运行并渲染图片的,请检查一下您的运行环境

image

vlssu commented

通过官方的 koishijs/koishi docker镜像搭建koishi后,基本上没有出现完全不能正常工作的问题了,但有一点不知道是我的问题还是插件本身。
在每次重启 koishi 的docker容器后,puppeteer并没有正常工作,需要手动禁用该插件并重新启用后才能正常工作。