Closed Bug 1173934 Opened 9 years ago Closed 9 years ago

ServiceWorker intercepted navigations that produce network errors should show an error message

Categories

(Core :: DOM: Service Workers, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla42
Tracking Status
firefox42 --- fixed

People

(Reporter: bkelly, Assigned: bkelly)

References

Details

(Whiteboard: [l10n])

Attachments

(2 files, 3 obsolete files)

Currently if a top level navigation is intercepted and the respondWith() Response is a network error then the tab just does nothing. It stays on the current page as if the link was never clicked. We should have some kind of network error or service worker error page instead. The UX is bad enough here I'm blocking v1, but of course we can debate that.
I think I have seen something like this... IIRC even if you copy the link, open a new tab, and paste it in the location bar and press Enter, nothing happens. I agree that we should fix this before shipping.
I'm going to see if I can just set an error code on the intercepted nsIChannel.
Assignee: nobody → bkelly
Status: NEW → ASSIGNED
Blocks: 1173912
So it turns out the FetchEvent.respondWith() was canceling the channel in all cases. Josh had an RAII style object to do that. The issue, however, was that the channel was canceled with NS_ERROR_ABORT_BINDING which docshell does not know about. Therefore, I created a new NS_ERROR_INTERCEPTION_FAILED result and modified nsDocShell to show an error page when this happens. The error page looks like this: https://www.dropbox.com/s/b8yce58v6e9d5z0/Screenshot%202015-07-02%2023.08.12.png?dl=0 I doubt users will really understand this, but I'm not sure what else to put here. I'm welcome to suggestions for other text.
Attachment #8629206 - Flags: review?(ehsan)
Do we translate messages like this? Flag l10n to check.
Whiteboard: [l10n]
Comment on attachment 8629206 [details] [diff] [review] Show a message if a docshell fails to load due to SW intercept failure. r=ehsan Review of attachment 8629206 [details] [diff] [review]: ----------------------------------------------------------------- It's great to be able to internally differentiate this kind of cancellation through NS_ERROR_INTERCEPTION_FAILED, and I think in nsDocShell::DisplayLoadError we should log a good error message to the console. However, I don't think we should show anything about service workers to the user, since this will be entirely meaningless for them. What do you think about reusing an existing error, such as corruptedContentError?
Attachment #8629206 - Flags: review?(ehsan) → review-
Well, in addition to that issue, these patches also don't work in e10s.
Ok. This now uses the corrupted content error page. It also logs to the console for various types of errors we know about. Of course, this logging is only done for navigations through docshell for now. In theory we could add this everywhere network requests are performed. Unfortunately we can't do it directly in ServiceWorkerEvents because we don't have the nsIDocument in order to find the console. For now I put it in a separate nsContentUtils method so we can add it in other places easily. Josh, can you review the nsIInterceptedChannel and InterceptedChannel bits? Ehsan, can you review the rest? Sorry I didn't have the foresight to split the patch up.
Attachment #8629206 - Attachment is obsolete: true
Attachment #8631112 - Flags: review?(josh)
Attachment #8631112 - Flags: review?(ehsan)
I'll add a test as well.
Actually, I'd like to just consolidate the test for this in the test I'm writing for bug 1173912.
Attachment #8631112 - Flags: review?(josh) → review+
Comment on attachment 8631112 [details] [diff] [review] Show a message if a docshell fails to load due to SW intercept failure. r=ehsan r=jdm Review of attachment 8631112 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/workers/ServiceWorkerEvents.cpp @@ +83,3 @@ > public: > + explicit CancelChannelRunnable(nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel, > + nsresult aStatus) Nit: please drop explicit.
Attachment #8631112 - Flags: review?(ehsan) → review+
Comment on attachment 8631112 [details] [diff] [review] Show a message if a docshell fails to load due to SW intercept failure. r=ehsan r=jdm Review of attachment 8631112 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/base/nsContentUtils.cpp @@ +3428,5 @@ > + } else if (aError == NS_ERROR_INTERCEPTED_ERROR_RESPONSE) { > + messageName = "InterceptedErrorResponse"; > + } else if (aError == NS_ERROR_INTERCEPTED_USED_RESPONSE) { > + messageName = "InterceptedUsedResponse"; > + } One small additional nit: Do you mind adding a MOZ_ASSERT(messageName) here so that we catch the cases where we forget to update this function in the future? Thanks!
Blocks: 1183162
Flags: needinfo?(bkelly)
Attachment #8632861 - Flags: review?(james)
Also updated existing patch to pass nsresult to nsIInterceptedChannel.cancel() to fix the netwerk xpcshell test: https://treeherder.mozilla.org/#/jobs?repo=try&revision=a194fb84d49b
Comment on attachment 8632861 [details] [diff] [review] Update wpt tests to expect failed window/frame on bad intercept. r=jgraham Review of attachment 8632861 [details] [diff] [review]: ----------------------------------------------------------------- ::: testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-frame-resource.https.html @@ +55,5 @@ > }); > }) > .then(function(frame) { > assert_equals( > + frame.contentDocument, If I have understood what's going on here, it's very unclear to me that either this or the previous behaviour are right. It seems like a CORS error should be something like a network error, which should end up at [1], which suggests that there should *be* a Document in the iframe, but that the contents of the DOM, if any are unspecified. Possibly the only right thing to do here is assert that the document we didn't expect to load did not in fact load, rather than trying to make positive assertions about what did load? [1] https://html.spec.whatwg.org/#read-ua-inline
Attachment #8632861 - Flags: review?(james)
James, what about this: assert_true( !frame.contentDocument || frame.contentDocument.textContent === '', /* ... */ ); How else do you propose to assert the document didn't load?
Flags: needinfo?(james)
https://html.spec.whatwg.org/#read-ua-inline The spec doesn't define in which domain the synthetic document should be. Is it same-origin to ... well what? or is it always cross-origin to any web pages?
To be honest, if this becomes a big issue over how gecko handles about:neterror and frame.contentDocument, I'm inclined to just mark these tests expected fail and hash that out in a separate bug.
Yeah, given the spec is very unclear about what the origin of the error page should be here, I think that stating that the contentDocument is either null or is a document that doesn't contain the content of the document that would hae loaded if the load had succeeded is perfectly reasonable. I can't see any reason to specifically expect the empty string though.
Flags: needinfo?(james)
Thinking about this some more, the *best* way to ensure that a cross-origin load doesn't happen is with a != reftest (the ref would be the same resource loaded same-origin), because the contentDocument === null check could be true even if the resource actually does load.
I'm using the check for empty string because I can't tell what the real resource is supposed to look like. We're missing fetch-access-control.py. I opened bug 1183677 for that.
Attachment #8632861 - Attachment is obsolete: true
Attachment #8633502 - Flags: review?(james)
Attachment #8633502 - Attachment is obsolete: true
Attachment #8633502 - Flags: review?(james)
Attachment #8633517 - Flags: review?(james)
Attachment #8633517 - Flags: review?(james) → review+
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
Blocks: 1215140
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: