Open yang093 opened 3 years ago
@yang093 does the comment @joshk0 helped you to fix your issue? Otherwise can you provide more information to help me reproduce your issue (code, commands, screenshot, error stacks, ...)?
@frinyvonnick just for context:
app_1 | Request GET /api/photos/602ab3320544daf2e61beb89 failed with status code 500. Error: Unable to launch browser, error message: Failed to launch the browser process!
app_1 | [0215/204717.308697:FATAL:zygote_host_impl_linux.cc(116)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/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.
app_1 | #0 0x5624452668f9 base::debug::CollectStackTrace()
app_1 | #1 0x5624451caae3 base::debug::StackTrace::StackTrace()
app_1 | #2 0x5624451dc865 logging::LogMessage::~LogMessage()
app_1 | #3 0x562446ac74ae service_manager::ZygoteHostImpl::Init()
app_1 | #4 0x562444db5627 content::ContentMainRunnerImpl::Initialize()
app_1 | #5 0x562444e032fa service_manager::Main()
app_1 | #6 0x562444db3c41 content::ContentMain()
app_1 | #7 0x562444e02135 headless::(anonymous namespace)::RunContentMain()
app_1 | #8 0x562444e01ddd headless::HeadlessShellMain()
app_1 | #9 0x562442870a67 ChromeMain
app_1 | #10 0x7fd3aa2322e1 __libc_start_main
app_1 | #11 0x5624428708aa _start
app_1 |
app_1 | Received signal 6
app_1 | #0 0x5624452668f9 base::debug::CollectStackTrace()
app_1 | #1 0x5624451caae3 base::debug::StackTrace::StackTrace()
app_1 | #2 0x5624452664a0 base::debug::(anonymous namespace)::StackDumpSignalHandler()
app_1 | #3 0x7fd3b07dc0e0 (/lib/x86_64-linux-gnu/libpthread-2.24.so+0x110df)
app_1 | #4 0x7fd3aa244fff gsignal
app_1 | #5 0x7fd3aa24642a abort
app_1 | #6 0x5624452653f5 base::debug::BreakDebugger()
app_1 | #7 0x5624451dcd04 logging::LogMessage::~LogMessage()
app_1 | #8 0x562446ac74ae service_manager::ZygoteHostImpl::Init()
app_1 | #9 0x562444db5627 content::ContentMainRunnerImpl::Initialize()
app_1 | #10 0x562444e032fa service_manager::Main()
app_1 | #11 0x562444db3c41 content::ContentMain()
app_1 | #12 0x562444e02135 headless::(anonymous namespace)::RunContentMain()
app_1 | #13 0x562444e01ddd headless::HeadlessShellMain()
app_1 | #14 0x562442870a67 ChromeMain
app_1 | #15 0x7fd3aa2322e1 __libc_start_main
app_1 | #16 0x5624428708aa _start
app_1 | r8: 0000000000000000 r9: 00007ffdcd45e950 r10: 0000000000000008 r11: 0000000000000246
app_1 | r12: 00007ffdcd45fc08 r13: 00007ffdcd45ebe0 r14: 00007ffdcd45fc10 r15: aaaaaaaaaaaaaaaa
app_1 | di: 0000000000000002 si: 00007ffdcd45e950 bp: 00007ffdcd45eb90 bx: 0000000000000006
app_1 | dx: 0000000000000000 ax: 0000000000000000 cx: 00007fd3aa244fff sp: 00007ffdcd45e9c8
app_1 | ip: 00007fd3aa244fff efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
app_1 | trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
app_1 | [end of stack trace]
app_1 | Calling _exit(1). Core file will not be generated.
app_1 |
app_1 |
app_1 | TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md
app_1 |
app_1 | at Cluster.<anonymous> (/home/node/app/node_modules/puppeteer-cluster/dist/Cluster.js:120:27)
app_1 | at Generator.throw (<anonymous>)
app_1 | at rejected (/home/node/app/node_modules/puppeteer-cluster/dist/Cluster.js:6:65)
app_1 | at processTicksAndRejections (internal/process/task_queues.js:97:5)```
Hey @frinyvonnick, @yang093, and @ilyapavkin! I was having the same issue a week back, but I was able to run it after using @joshk0 's tip and looking around for a bit. Using this code, I was able to create this Dockerfile:
FROM zenika/alpine-chrome:with-node
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium-browser
WORKDIR /usr/src/app
COPY --chown=chrome package*.json ./
RUN npm install
COPY --chown=chrome . ./
ENTRYPOINT ["tini", "--"]
CMD ["npm", "start"]
Also, these were the puppeteer args I added to the function, since the function wasn't running in the container before I did this:
puppeteerArgs: {
headless: true,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--headless",
"--disable-gpu",
"--disable-dev-shm-usage",
],
},
I hope this helps!
It could be interesting to add explanations on this topic in the README?
@sBx99 suggestion worked for me.
Fonts were not working after using alpine-chrome, so I needed to do a little hacking to manually add (because I am using special fonts for this project) all the fonts into /usr/share/fonts folder on docker container. Please be aware that you need to have root privileges in order to create a folder inside /usr/share/fonts and copy your fonts inside. If you are using Google Fonts, you can just add it to your dockerfile.
This is my docker file:
`FROM node:16-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN apk update && \
apk upgrade -U && \
apk add ca-certificates ffmpeg libwebp libwebp-tools && \
rm -rf /var/cache/*
RUN apk add python3
RUN apk add build-base
RUN npm install
COPY . .
RUN npm run build
CMD ["node", "dist/main"]`
I'm getting is error:
I tried different solutions but it's not working, Can someone tell how can I fix this? I tried the solution above but I think I'm missing something
nodeHtmlToImage({
html: content,
puppeteerArgs: {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu'
]
}
})
when i set the puppeteerArgs in nodeHtmlToImage func, i fix this. I hope this helps!
@Nixum Thanks
Gotten things working on a Rpi 4 arm64 running docker Here is my dockerfile and htmltoimage options
`FROM node:17.4.0 ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1 ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium
WORKDIR /app COPY package.json /app RUN npm install puppeteer RUN npm install RUN apt-get update RUN apt-get install chromium --yes COPY . /app EXPOSE 3001 CMD ["npm", "start"]
puppeteerArgs: { headless: true, args: [ "--no-sandbox", "--disable-setuid-sandbox", "--headless", "--disable-gpu", "--disable-dev-shm-usage", ] }`
I'm struggling to get this to work on latest version (including building latest commit) even with some of the tips in this thread. Trying older versions of puppateer. The latest version on alpine I think is not possible to get working. I'm trying older versions that have older versions of puppateer now.
@roninjin10
You can try getting into your container and find if the chromium is in the correct location /usr/bin/chromium
or somewhere else.
You can also check it's chromium-browser
or just chromium
I'm using node:16-alpine
and it's working.
RUN apk add chromium
puppeteerArgs: {
executablePath: '/usr/bin/chromium-browser',
args: ['--no-sandbox', '--disable-setuid-sandbox'],
}
@ZainUrRehmanKhan Yea still having issues. Your advice was good though. chromium-browser vs chromium was a bug.
Dockerfile
FROM --platform=linux/x86-64 node:16.17.1-alpine3.15 as base
RUN apk update && \
apk upgrade -U \
ca-certificates ffmpeg libwebp libwebp-tools
RUN apk --no-cache add chromium
RUN apk --no-cache add curl jq python3 ca-certificates git make gcc musl-dev linux-headers bash build-base
WORKDIR /opt/optimism
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium-browser
ENV CHROME_BIN /usr/bin/chromium-browser
COPY tsconfig.json package.json yarn.lock .npmrc ./
COPY packages/contracts/package.json packages/contracts/tsconfig.json packages/contracts/
COPY packages/nft-image-render/package.json packages/nft-image-render/tsconfig.json packages/nft-image-render/
COPY packages/tokenlist packages/tokenlist/
COPY packages/backend/package.json packages/backend/tsconfig.json packages/backend/
RUN yarn install --frozen-lockfile
# Build @gateway/backend & @gateway/contracts
COPY ./packages/contracts packages/contracts/
COPY ./packages/nft-image-render packages/nft-image-render/
COPY ./packages/backend packages/backend/
COPY ./packages/tokenlist packages/tokenlist/
RUN yarn workspace @gateway/backend run build
# Start @gateway/backend
EXPOSE $PORT
CMD ["yarn", "workspace", "@gateway/backend","run", "start:ci"]
And here is my code
return nodeHtmlToImage({
type: 'png',
// .nft-image-render
selector: `.${nftImageClass}`,
puppeteerArgs: {
headless: true,
executablePath: '/usr/bin/chromium-browser',
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-sandbox',
'--headless',
],
},
html: `
<!DOCTYPE html>
<html lang="en">
<head>
<style>
${nftImageCss}
</style>
</head>
<body>
${ReactDOMServer.renderToString(
<NFTImageRender
isPNG={false}
imageUri={imageUri}
{...optimistNftProps}
/>,
)}
</body>
</html>`,
})
And this is puppeteer debug data
puppeteer:launcher Calling /usr/bin/chromium-browser --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,BackForwardCache --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --enable-blink-features=IdleDetection --export-tagged-pdf --headless --hide-scrollbars --mute-audio about:blank --disable-gpu --disable-dev-shm-usage --disable-setuid-sandbox --no-sandbox --headless --remote-debugging-port=0 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-nMaaED +6s
puppeteer:protocol:SEND ► {"method":"Target.setDiscoverTargets","params":{"discover":true},"id":1} +6s
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"1C9B35F22267E15EA3DEC508BF85C7D1","type":"page","title":"","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"5BA88B5B64652B58A72981B484CAF7DB"}}} +6s
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"525a8844-cc00-4a61-af7e-cb143cb13a4d","type":"browser","title":"","url":"","attached":false,"canAccessOpener":false}}} +3ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"6d82dc65-be09-42b9-8b08-151d6cb69d5e","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}} +0ms
puppeteer:protocol:RECV ◀ {"id":1,"result":{}} +1ms
puppeteer:protocol:SEND ► {"method":"Target.createBrowserContext","params":{},"id":2} +252ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCrashed","params":{"targetId":"1C9B35F22267E15EA3DEC508BF85C7D1","status":"failed to launch","errorCode":1002}} +47ms
puppeteer:protocol:RECV ◀ {"id":2,"result":{"browserContextId":"4406173E18BBBC223DE4318130621333"}} +16ms
puppeteer:protocol:SEND ► {"method":"Target.createTarget","params":{"url":"about:blank","browserContextId":"4406173E18BBBC223DE4318130621333"},"id":3} +62ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"5203436A7748BCD9FE7D37D226D6F6C6","type":"page","title":"","url":"","attached":false,"canAccessOpener":false,"browserContextId":"4406173E18BBBC223DE4318130621333"}}} +23ms
puppeteer:protocol:RECV ◀ {"id":3,"result":{"targetId":"5203436A7748BCD9FE7D37D226D6F6C6"}} +12ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCrashed","params":{"targetId":"5203436A7748BCD9FE7D37D226D6F6C6","status":"failed to launch","errorCode":1002}} +16ms
puppeteer:launcher Calling /usr/bin/chromium-browser --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,BackForwardCache --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --enable-blink-features=IdleDetection --export-tagged-pdf --headless --hide-scrollbars --mute-audio about:blank --disable-gpu --disable-dev-shm-usage --disable-setuid-sandbox --no-sandbox --headless --remote-debugging-port=0 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-GpKnED +6s
puppeteer:protocol:SEND ► {"method":"Target.setDiscoverTargets","params":{"discover":true},"id":1} +6s
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"7B3126F2EB203BC08387DDAFC9C6B619","type":"page","title":"","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"9D249926EDE842FE2A10BB3A1741B32B"}}} +6s
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"888c759a-4727-45ac-bb3f-df9ddb028333","type":"browser","title":"","url":"","attached":false,"canAccessOpener":false}}} +1ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"de25afcb-4058-42c6-95c0-ae57eb6da9ef","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}} +1ms
puppeteer:protocol:RECV ◀ {"id":1,"result":{}} +0ms
puppeteer:protocol:SEND ► {"method":"Target.createBrowserContext","params":{},"id":2} +261ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCrashed","params":{"targetId":"7B3126F2EB203BC08387DDAFC9C6B619","status":"failed to launch","errorCode":1002}} +47ms
puppeteer:protocol:RECV ◀ {"id":2,"result":{"browserContextId":"732287699F2FC4E6A792A8B0B2DF1156"}} +15ms
puppeteer:protocol:SEND ► {"method":"Target.createTarget","params":{"url":"about:blank","browserContextId":"732287699F2FC4E6A792A8B0B2DF1156"},"id":3} +61ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"8AF5FD608EDAE8E6BDED20427738B0C8","type":"page","title":"","url":"","attached":false,"canAccessOpener":false,"browserContextId":"732287699F2FC4E6A792A8B0B2DF1156"}}} +22ms
puppeteer:protocol:RECV ◀ {"id":3,"result":{"targetId":"8AF5FD608EDAE8E6BDED20427738B0C8"}} +12ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCrashed","params":{"targetId":"8AF5FD608EDAE8E6BDED20427738B0C8","status":"failed to launch","errorCode":1002}} +15ms
My latest run got a different error
I changed the options to this:
headless: true,
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-sandbox',
'--headless',
],
And got this error which is different
[
{
"error": {
"json": {
"message": "Unable to launch browser, error message: Failed to launch the browser process!\nqemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped\nqemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped\n[1201/204236.827090:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory\n[1201/204236.834224:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory\n[1201/204236.866902:warning:dns_config_service_linux.cc(427)] Failed to read DnsConfig.\n[1201/204236.908122:ERROR:egl_util.cc(74)] Failed to load GLES library: /usr/lib/chromium/libGLESv2.so: Error loading shared library /usr/lib/chromium/libGLESv2.so: No such file or directory\nAssertion 'r == 0 || r == 95' failed at ../src/pulsecore/mutex-posix.c:57, function pa_mutex_new(). Aborting.\nqemu: uncaught target signal 6 (Aborted) - core dumped\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n",
"code": -32603,
"data": {
"code": "INTERNAL_SERVER_ERROR",
"httpStatus": 500,
"path": "nftbuilder.upload"
}
}
}
}
]
In version 4.0.0 I updated puppeeteer to version 21.0.1. It might help you in some way?
Oh I did get this working. Forgot to update. Here. If anybody has issues ping me and I can send you the combination of dockerfile plus runtime config that got it working.
One issue I had btw was that I had a working docker config multiple times following advice in this thread but it still failed on macOS on mac silicone specifically without me realizing it was macOS based issues
Why can't you post it here @roninjin10?
I had success running it in a Docker container. I started from zenika/alpine-chrome:with-node and made sure to set the arguments: