admin管理员组文章数量:1208153
puppeteer is killing my page when I call setContent
.
How can I debug why this is happening?
code:
chrome = await puppeteer.launch();
page = await chrome.newPage();
await page.setUserAgent(ua);
await page.setViewport({width: Number(width), height: Number(height)});
console.warn("here4");
if (input) {
console.warn("input found");
await page.setContent(input);
}
console.warn("here5");
log:
2025-01-20T00:54:47.099Z puppeteer:browsers:launcher Launching /home/user/.cache/puppeteer/chrome-headless-shell/linux-132.0.6834.83/chrome-headless-shell-linux64/chrome-headless-shell --allow-pre-commit-input --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-crash-reporter --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-search-engine-choice-screen --disable-sync --enable-automation --export-tagged-pdf --force-color-profile=srgb --generate-pdf-document-outline --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes --enable-features=PdfOopif --headless --hide-scrollbars --mute-audio about:blank --remote-debugging-port=0 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-BQX8Ok { detached: true, env: {}, stdio: [ 'pipe', 'ignore', 'pipe' ] }
2025-01-20T00:54:47.116Z puppeteer:browsers:launcher Launched 2692983
here4
input found
2025-01-20T00:54:47.490Z puppeteer:browsers:launcher Trying to kill 2692983
2025-01-20T00:54:47.490Z puppeteer:browsers:launcher Browser process 2692983 exists
/home/user/v14-staging/apps/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:80
this._reject(callback, new Errors_js_1.TargetCloseError('Target closed'));
EDIT: The function that prints "Trying to kill" is kill() on the Process class .ts#L408 However, it looks like this is simply reacting to the target being closed.
In the protocol trace, after I do page.setViewport
I see:
2025-01-21T00:02:12.267Z puppeteer:protocol:SEND ► [
'{"method":"Target.closeTarget","params":{"targetId":"F8275C626B6FC4F650B5D03DA59FECD9"},"id":4}'
]
But I'm not sending that in my code
There are only two places in the code that send this, webworker and page. Most logical place is page here: .ts#L1143
So looks like something is calling page.close() after I call page.setViewport
EDIT2: Having messed around with the code it looks like something is calling page.close() if I just wait after opening the page
puppeteer is killing my page when I call setContent
.
How can I debug why this is happening?
code:
chrome = await puppeteer.launch();
page = await chrome.newPage();
await page.setUserAgent(ua);
await page.setViewport({width: Number(width), height: Number(height)});
console.warn("here4");
if (input) {
console.warn("input found");
await page.setContent(input);
}
console.warn("here5");
log:
2025-01-20T00:54:47.099Z puppeteer:browsers:launcher Launching /home/user/.cache/puppeteer/chrome-headless-shell/linux-132.0.6834.83/chrome-headless-shell-linux64/chrome-headless-shell --allow-pre-commit-input --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-crash-reporter --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-search-engine-choice-screen --disable-sync --enable-automation --export-tagged-pdf --force-color-profile=srgb --generate-pdf-document-outline --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes --enable-features=PdfOopif --headless --hide-scrollbars --mute-audio about:blank --remote-debugging-port=0 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-BQX8Ok { detached: true, env: {}, stdio: [ 'pipe', 'ignore', 'pipe' ] }
2025-01-20T00:54:47.116Z puppeteer:browsers:launcher Launched 2692983
here4
input found
2025-01-20T00:54:47.490Z puppeteer:browsers:launcher Trying to kill 2692983
2025-01-20T00:54:47.490Z puppeteer:browsers:launcher Browser process 2692983 exists
/home/user/v14-staging/apps/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:80
this._reject(callback, new Errors_js_1.TargetCloseError('Target closed'));
EDIT: The function that prints "Trying to kill" is kill() on the Process class https://github.com/puppeteer/puppeteer/blob/89f4f3b1079874b2dd91c727bc058c1b6e09096e/packages/browsers/src/launch.ts#L408 However, it looks like this is simply reacting to the target being closed.
In the protocol trace, after I do page.setViewport
I see:
2025-01-21T00:02:12.267Z puppeteer:protocol:SEND ► [
'{"method":"Target.closeTarget","params":{"targetId":"F8275C626B6FC4F650B5D03DA59FECD9"},"id":4}'
]
But I'm not sending that in my code
There are only two places in the code that send this, webworker and page. Most logical place is page here: https://github.com/puppeteer/puppeteer/blob/89f4f3b1079874b2dd91c727bc058c1b6e09096e/packages/puppeteer-core/src/cdp/Page.ts#L1143
So looks like something is calling page.close() after I call page.setViewport
EDIT2: Having messed around with the code it looks like something is calling page.close() if I just wait after opening the page
Share Improve this question edited Jan 21 at 0:40 racitup asked Jan 20 at 1:17 racitupracitup 4544 silver badges12 bronze badges 2 |1 Answer
Reset to default 0It looks like puppeteer doesn't like you calling page.setViewport
before having any content loaded.
If you do it looks like page.close() is called.
If anyone is trying to debug problems with puppeteer I recommend starting it with this line from a shell:
env DEBUG="puppeteer:*" node puppeteer_script.js "$@" <&0
This should help you find the problem.
EDIT:
Actually scratch my above answer.
I think the real reason for the early termination was that I was using an async function to do a screenshot, but forgot the await
on the call.
So the parent function was closing the browser before the promise resolved.
本文标签: puppeteerbrowserslauncher Trying to killStack Overflow
版权声明:本文标题:puppeteer:browsers:launcher Trying to kill - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738720150a2108693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
input
and browser launch settings are causing this, or is this on anyinput
? If it's any input, that's not normall, so system details would likely be relevant. Does this fail ongoto
as well? Please isolate the problem and provide a package.json. Thanks. – ggorlen Commented Jan 20 at 2:21