-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
page.goto returns null periodically #2479
Comments
@ntzm Thanks for filing this separately, I can easily repro this. You can workaround using |
Thanks! |
Here's an even simpler way to reproduce it: const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// const Url = "https://www.peterbe.com/#anything"; // FAILS
const Url = "https://www.peterbe.com#anything"; // ALSO FAILS
// const Url = "https://www.peterbe.com"; // WORKS
const r1 = await page.goto(Url, { waitUntil: "domcontentloaded" });
if (r1 === null) console.log("Response is null!");
else console.log("Response OK?", r1.ok());
const r2 = await page.goto(Url, { waitUntil: "domcontentloaded" });
if (r2 === null) console.log("Response is null!");
else console.log("Response OK?", r2.ok());
await browser.close();
})(); Output is:
Every time. Note that removing the anchor part of the Note, I don't think it's related to |
Actually, regarding my above example of reproducing it. If you comment out the first request (or second, doesn't matter) so it looks like this: const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// const Url = "https://www.peterbe.com/#anything"; // FAILS
const Url = "https://www.peterbe.com#anything"; // ALSO FAILS
// const Url = "https://www.peterbe.com"; // WORKS
const r1 = await page.goto(Url, { waitUntil: "domcontentloaded" });
if (r1 === null) console.log("Response is null!");
else console.log("Response OK?", r1.ok());
// const r2 = await page.goto(Url, { waitUntil: "domcontentloaded" });
// if (r2 === null) console.log("Response is null!");
// else console.log("Response OK?", r2.ok());
await browser.close();
})(); Then it works. So, pretty sure the |
@peterbe I am curious if you also got this error when using it on a URL that does not have (or which you intercept via Puppeteer) Google Analytics, Intercom, etc? I am also experiencing this issue: that is: when |
@bluepeter I had a similar issue trying to use an unsupported version of Chrome |
This happens for us too, when using Interestingly, using a context (ie |
Here's a bit of a workaround until this is fixed:
|
@bluepeter that workaround works for me, thanks a lot |
@ntzm somehow it doesn't reproduce for me anymore on v1.8.0. Here's my script: const puppeteer = require('puppeteer');
const url = 'https://www.microsoft.com/en-gb/store/d/xbox-one-s-1tb-console-playerunknowns-battlegrounds-bundle/908z9jn5cnh2/gz4w?cid=msft_web_collection';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
for (var i = 0; i < 30; i++) {
const r = await page.goto(url, { waitUntil: 'domcontentloaded' });
console.log(!!r);
}
await browser.close();
})(); @peterbe I looked into your script. We're actually quite consistent with chromium here:
This might be surprising, but this is consistent with what happens if user types in the address bar. if you want to force-load a website, I'd open a new page and navigate it instead. |
Yep, I can confirm this works on 1.8.0! |
@alphonse92 can you share the URL that doesn't work? |
@aslushnikov Hi, sorry, it was my fault, the problem was the ssl certificates and chromium is killing the request. |
@aslushnikov still broken with 1.20. This returns null everytimes const puppeteer = require('puppeteer');
const url = 'https://havgaarden.dk/restaurant';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const response = await page.goto(url, {
timeout: 15000,
waitUntil: 'domcontentloaded'
});
if (!response) console.log('null response');
await browser.close();
})(); Note that this website features a redirection initiated by javascript |
is it possible the server just ends the connection earlier than expected? something like https://httpstatuses.com/444 but more subtle or silent?
|
@jtara1 that sounds unlikely, for me it happens everytime that a page has a redirection initiated by javascript after the event |
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'request' of null at /opt/inspection/website-evidence-collector/website-evidence-collector.js:196:40 at process._tickCallback (internal/process/next_tick.js:68:7) Solution from: puppeteer/puppeteer#2479 (comment)
It seems this problem has something todo with caching. When I create a createIncognitoBrowserContext for every request. This never happens. Since I removed that extra context. This Problem happened also to me. |
wow... it's working... it's weird that we need to make new context for every request... I hope it will be fixed soon |
You dont need the context. Just call page.setCacheEnabled(false). From my limited tests, it seems to do the same. |
I see... I'll try it |
ah yes... I can confirm it's working thanks! :D |
wait... I'm mistaken, it's not working with page.setCacheEnabled(false) |
It is not working with
yields the perfect results. I'm afraid to change it now, but some of that, such as Thanks to all in this thread. |
This will return the first response you're getting once interception starts. This will NOT return the intial request you're actually looking. So if you actually need that request, you're out of luck unless you use an incognito tab. |
In my case I was accessing different pages of an SPA where the pages were after the hash symbol. There's a footnote in puppeteer documentation about goto that says the following:
What I did as a temporary workaround was to force the page to go somewhere else (e.g. 'about:blank') and then 'goto' the page I wanted to test. Something like this: if (response === null) {
await page.goto('about:blank');
response = await page.goto(urlWithHash);
} This doesn't seem optimal since it downloads the entire page again but the crawling system I'm working on depends on the response data for every single page, so that works. |
In my case the The first time it works, the second time it already returns null. You have to delete the chrome data to remove the SW const puppeteer = require('puppeteer');
const url = 'https://whatpwacando.today/';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const response = await page.goto(url, {
timeout: 15000,
waitUntil: 'domcontentloaded'
});
if (!response) console.log('null response');
await browser.close();
})(); |
FWIW, If you could have an issue due to service workers, over at playwright they have the ability to block the service worker registration (but maybe the real issue is that page.goto still returns the wrong 'frame') |
Steps to reproduce
Similar/same as: #1391
Tell us about your environment:
What steps will reproduce the problem?
What is the expected result?
true
outputted 15 timesWhat happens instead?
Sometimes
true
15 times, sometimesTypeError: Cannot read property 'ok' of null
It works as expected on 1.2.0, but fails on 1.3.0
The text was updated successfully, but these errors were encountered: