Open Bug 1914407 Opened 2 months ago Updated 1 day ago

Improve error message when navigation fails due to a window.location update

Categories

(Remote Protocol :: WebDriver BiDi, defect, P2)

defect
Points:
2

Tracking

(Not tracked)

ASSIGNED

People

(Reporter: whimboo, Assigned: jdescottes)

References

(Blocks 3 open bugs)

Details

(Whiteboard: [webdriver:m13])

Attachments

(3 files, 1 obsolete file)

Originally filed at: https://github.com/puppeteer/puppeteer/issues/12929

We should check what exactly is causing us to fail the navigation command.

Attached file BCWebProgress:5 log

The problem here seems to be the redirect to https://twitter.com. Not sure how this is done but it looks like it's not a usual redirect, but maybe they manually call window.location as well?

Actually using DevTools network monitor the raw response from loading https://x.com shows indeed that window.location.href is used but there is also a call to replaceState. Not sure which exactly is executed here.

This bug seems to rely on the same underlying discussion as bug 1914405.

Severity: -- → S3
Points: --- → 3
Depends on: 1914405
Priority: -- → P2
Whiteboard: [webdriver:m12]
Blocks: 1914405
No longer depends on: 1914405
Assignee: nobody → jdescottes
Status: NEW → ASSIGNED

I tried to investigate a bit why nsIRequest.canceledReason didn't give any extra info here.
When the load is interrupted by a window.location update, as pointed out by :Nika, the docshell will stop the load at https://searchfox.org/mozilla-central/rev/cc01f11adfacca9cd44a75fd140d2fdd8f9a48d4/docshell/base/nsDocShell.cpp#9388-9401

// Stop any current network activity.
// Also stop content if this is a zombie doc. otherwise
// the onload will be delayed by other loads initiated in the
// background by the first document that
// didn't fully load before the next load was initiated.
// If not a zombie, don't stop content until data
// starts arriving from the new URI...

if ((mDocumentViewer && mDocumentViewer->GetPreviousViewer()) ||
    LOAD_TYPE_HAS_FLAGS(aLoadState->LoadType(), LOAD_FLAGS_STOP_CONTENT)) {
  rv = Stop(nsIWebNavigation::STOP_ALL);
} else {
  rv = Stop(nsIWebNavigation::STOP_NETWORK);
}

And interestingly, we actually cancel the requests with a proper reason "nsDocLoader::Stop". While this wouldn't be enough to differentiate between a stop due to a navigation and one due to the user canceling the navigation (eg clicking on the cancel icon or pressing escape), it would still be interesting to have this reason available to our Navigation helper.

However the request available from the WebProgress in the parent process is a RemoteWebProgressRequest, which is not the real request, and this request doesn't have the proper canceledReason set.

Nika, Valentin: do you know if we could get the canceledReason for the real request and set it correctly on the RemoteWebProgressRequest?

[On the other hand, I tried to check if we could reuse our NavigationManager to detect the new navigation, but sadly in the parent process we seem to get the notification about the new navigation after we get NS_ABORTED.]

Flags: needinfo?(valentin.gosu)
Flags: needinfo?(nika)

(In reply to Julian Descottes [:jdescottes] from comment #4)

Nika, Valentin: do you know if we could get the canceledReason for the real request and set it correctly on the RemoteWebProgressRequest?

RemoteWebProgressRequest is a tiny type used for web progress listeners in the parent process, so doesn't have any extra details on it beyond the basic mURI, mOriginalURI, and mMatchedList (https://searchfox.org/mozilla-central/rev/90dc3743ea284c258148124dc54dfd123e82586f/dom/ipc/RemoteWebProgressRequest.h#29-32). While the mCanceledReason exists because of being on nsIRequest, it is not included in the RequestData struct sent over IPC (https://searchfox.org/mozilla-central/rev/90dc3743ea284c258148124dc54dfd123e82586f/dom/ipc/PBrowser.ipdl#125-130), and therefore isn't transferred across processes.

If this is something which you think would be valuable to have available on remote web progress notifications, we could add it as an extra piece of information being sent down, but we unfortunately can't easily have a "real" channel available on these progress notifications.

Flags: needinfo?(nika) → needinfo?(jdescottes)

Thanks for the feedback, let's discuss this during triage today. I think that would allow us to at least craft a better error message, and potentially wait for the next navigation (although our spec currently doesn't support this).

Whiteboard: [webdriver:m12] → [webdriver:triage][webdriver:m12]

After discussing we agree it would be great to have the canceled reason on this request, and based on this we will emit a better error message. We should also add a wdspec test for this.

Also we should probably write a script to check how BiDi behaves when navigating to eg the top 1000 sites.

Flags: needinfo?(jdescottes)
Flags: needinfo?(valentin.gosu)
Whiteboard: [webdriver:triage][webdriver:m12] → [webdriver:m12]

Interestingly, when writing a wdspec test to reproduce the issue, I also get a failure with chrome:

future     = <Future finished exception=UnknownErrorException(unknown error, navigation canceled, as new navigation is requested by scriptInitiated, Error
    at new UnknownErrorException (<anonymous>:81:4591)
    at <anonymous>:597:6717
    at <anonymous>:1:1010
    at Array.map (<anonymous>)
    at Object.emit (<anonymous>:1:993)
    at MapperCdpClient.emit (<anonymous>:17:387)
    at #onMessage (<anonymous>:823:2977)
    at WindowCdpTransport.window.cdp.onmessage (<anonymous>:888:4763)
    at <anonymous>:1:18)>

Maybe this doesn't occur in puppeteer because of specific feature which gets enabled in Chrome by puppeteer?

And I also get the same when connecting the client from https://juliandescottes.github.io/bidi-web-client/web/ to a regular Chrome instance and doing a navigation to mozilla.org.

So at least the behavior seems consistent in both browsers, although arguably the error message is much more helpful in Chrome.

The canceledReason is added to the RequestData used to build the
RemoteWebProgressRequest. This canceledReason is useful for consumers such
as WebDriverBiDi which need to emit different error messages depending on
the reason why a specific navigation request was canceled.

Blocks: 1921119

Comment on attachment 9426551 [details]
Bug 1914407 - Add canceledReason to RemoteWebProgressRequest

Revision D223174 was moved to bug 1921119. Setting attachment 9426551 [details] to obsolete.

Attachment #9426551 - Attachment is obsolete: true
No longer blocks: 1921119
Depends on: 1921119
Points: 3 → 2
Whiteboard: [webdriver:m12] → [webdriver:m13]

Cool! so this is an update on firefox that will help me run puppeteer with it as announced here? https://hacks.mozilla.org/2024/08/puppeteer-support-for-firefox/

Blocks: 1921973
Summary: NS_BINDING_ABORTED error when navigating to https://x.com → Improve error message when navigation fails due to a window.location update

(In reply to amunizp from comment #13)

Cool! so this is an update on firefox that will help me run puppeteer with it as announced here? https://hacks.mozilla.org/2024/08/puppeteer-support-for-firefox/

You are already able to use Puppeteer with Firefox via the Webdriver BiDi protocol. It's just that in some cases websites do quirky stuff like setting window.location to a different URL itself to trigger kinda redirect. That currently fails and bug 1921973 got filed for that. Here we are only updating the error message to make it more clear to the user why the call to the browsingContext.navigate command failed.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: