-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Hash-only navigation doesn't work #257
Comments
Hash navigation breaks all our navigation primitives: page.waitForNavigation();
page.goto();
page.goForward();
page.goBack(); |
I've seen this in just about every headless driver out there, and am suspecting it's an issue in the browser itself... |
This patch teaches the following methods to support anchor navigation: - `page.goto` - `page.waitForNavigation` - `page.goBack` - `page.goForward` Fixes puppeteer#257.
@aslushnikov I got the same issue, has this issue been solved? |
When it is solved the issue will be updated with further information in regards to it. |
I am not sure if this is completely relevant to this thread, but I just created a script that allows us to navigate to hashes on a page to take various screenshots. The reason I question the relevance is because we have some JS working in the background that assists our navigation, so I don't know if this script would work without the page JS or not. Anyway, here is what works for me (sorry, it is node6):
Using a the browser inspector and Charles it appears that the only network traffic this creates is to make the initial call to the server. After that has rendered the network goes quiet. This is a solution for the issue I was trying to solve that lead me to #491 -- which brought me here. I hope this helps someone. |
@Garbee thanks! |
@onamission thanks! It is works for me. await page.goto(tag.url, {waitUntil: 'networkidle'}) |
And with the history API // page
history.pushState(null, null, url);
// puppeteer
await page.goBack(); // <= BTW, |
@Means88 This works as a workaround: await page.goto(url, {waitUntil: 'networkidle'})
const url = await page.evaluate('location.href'); |
Will the problem of anchor navigations be solved in 0.13? |
The incompatibility with History means that sites using Here are some of my workarounds: I use I use these two functions for dealing with the URL const getLocation = async (page) => page.evaluate(() => location)
const getLocationProp = async (page, prop) => (await getLocation(page))[prop] and these for history: const getHistory = async (page) => page._client.send('Page.getNavigationHistory')
const getHistoryEntry = async (page, index) => (await getHistory(page)).entries[index]
const getCurrentHistoryEntry = async (page) => {
const { entries, currentIndex } = await getHistory(page)
return entries[currentIndex]
} |
I'm running into this issue trying to take screenshots of our production SPA for a perceptual diff test. If there's any way to help track down the root source of this weird behavior (goto not working within an app is bothersome), please point me in the right direction and I'll try to fix it. |
It’s an issue in chromes remote protocol. I think/hope they’re looking into it. As an alternative, for the time being, I think you can monitor network inactivity and take your screenshot when that’s silent. By no means a permanent solution, but should hopefully get you by in the meantime |
Using Note that the documentation says :
But these parameters don't seem to work... |
Switching between different versions of Puppeteer... Result:
So it looks like there is a regression with lastest versions, or I don't understand the new options... |
This is related to a problem in chrome's protocol. In short, hash navigation won't trigger any of the page initialization events. A puppeteer problem is that page.goto FORCES you to attempt to listen to one of those events (unless there's some undocumented configuration option), timing out with an error if (when) they never come. The only reliable way around this is to set a low timeout, catch (and disregard) the error that will come, and then manually check if the page has loaded with your own logic. Is there some way around this? |
How to solve the problem in the new version(1.1.1)? thank you. |
https://github.com/GoogleChromeLabs/puppeteer-examples/blob/master/hash_navigation.js shows how to listen for |
@ebidel Thank you very much. |
Version: 1.1.1 Just to add to this, cause I don't think anyone mentioned it yet, but this also seems to cause problems with SPAs that use HTML5-style URLs and coupled with waitForNavigation. Originally we were doing this: await page.goto(`${domain}/${path}`, { waitUntil: 'networkidle0' }); But as observed without headless, you're losing the performance benefit of an SPA as every page gets entirely loaded again. So I've added this to speed up page-switching if a link exists it'll be clicked instead so a full reload doesn't occur: const link = await page.$(`a[href="${path}"]`);
if (link) {
return await Promise.all([
page.waitForNavigation({ waitUntil: 'networkidle0' }),
link.click(),
]);
}
await page.goto(`${domain}/${path}`, { waitUntil: 'networkidle0' }); The clicks work and everything is fast, but the waitForNavigation never resolves. We're using URLs like: www.mysite.com, www.mysite.com/contact, www.mysite.com/about-us so this doesn't seem to be limited to hashed URLs Not even the following works: await Promise.all([
page.waitForNavigation({ waitUntil: 'networkidle0' }),
new Promise(resolve => setTimeout(() => resolve(link.click()), 500)),
]); Workaround is to enforce waitFor function selectors throughout to determine page readiness but was hoping to re-use the networkidle0 functionality. Perhaps that could be allowed in a standard waitFor call? With workaround though, you have missing images in screenshots as you're unable to wait for all network requests to finish Maybe related to: #1412 |
This roll includes: - https://crrev.com/548598 - DevTools: implement Page.setBypassCSP method - https://crrev.com/548690 - DevTools: introduce Page.navigatedWithinDocument event References puppeteer#1229, puppeteer#257.
This roll includes: - https://crrev.com/548598 - DevTools: implement Page.setBypassCSP method - https://crrev.com/548690 - DevTools: introduce Page.navigatedWithinDocument event References #1229, #257.
This patch fixes puppeteer navigation primitives to work with same-document navigation. Same-document navigation happens when document's URL is changed, but document instance is not re-created. Some common scenarios for same-document navigation are: - History API - anchor navigation With this patch: - pptr starts dispatching `framenavigated` event when frame's URL gets changed due to same-document navigation - `page.waitForNavigation` now works with same-document navigation - `page.goBack()` and `page.goForward()` are handled correctly. Fixes puppeteer#257.
This patch fixes puppeteer navigation primitives to work with same-document navigation. Same-document navigation happens when document's URL is changed, but document instance is not re-created. Some common scenarios for same-document navigation are: - History API - anchor navigation With this patch: - pptr starts dispatching `framenavigated` event when frame's URL gets changed due to same-document navigation - `page.waitForNavigation` now works with same-document navigation - `page.goBack()` and `page.goForward()` are handled correctly. Fixes #257.
Guys can this issue affect my test? For GUID login testing im trying to go to URL 'http://www.obgyn.net?25AA8E3E' but actual navigation is going to http://www.obgyn.net/?25AA8E3E so its braking my testing. Is there any solution to get rid of '/' before '?' mark ? Thanks in advance |
maximkoshelenko, I think URL without path (slash /) simply incorrect. |
For those who don't want to fight with pptr
|
Since the hash-only navigation doesn't cause any network requests and doesn't cause load event,
the following gets stuck:
The text was updated successfully, but these errors were encountered: