Skip to content
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

fetchEvent.type = "navigate" is confusing #140

Closed
jakearchibald opened this issue Jan 7, 2014 · 18 comments
Closed

fetchEvent.type = "navigate" is confusing #140

jakearchibald opened this issue Jan 7, 2014 · 18 comments

Comments

@jakearchibald
Copy link
Contributor

Feels like both "type" and "fetch" are wrong here.

Maybe "type" should be "origin", and "fetch" is "resource"?

So:

this.onfetch = function(event) {
  if (event.origin == 'resource') {
    // ...
  }
}
@annevk
Copy link
Member

annevk commented Jan 7, 2014

Isn't the type of event a "fetch"? The type is always the name of the event being dispatched.

@annevk
Copy link
Member

annevk commented Jan 7, 2014

And origin should really never be anything but the scheme/host/port tuple.

@jakearchibald
Copy link
Contributor Author

@annevk: Right, type should always be "fetch", that's why the current API is confusing. It currently uses type to differentiate between fetched that resulted from navigations.

See your point about "origin". Any better ideas?

@annevk
Copy link
Member

annevk commented Jan 7, 2014

I thought the idea with navigate was that navigate causes a fetch but you can decide to handle it all from the navigate event? (If we ever do that...)

@jakearchibald
Copy link
Contributor Author

The navigate event might be implemented later, but you want to know in the fetch event if the fetch was caused by a navigate.

The use case is serving a helpful "You're offline and that page isn't available" page when the user navigates, but not on xhr etc. Also, could be used if the user navigates to an RSS feed, you could use it to display a page explaining how RSS should be used.

@jakearchibald
Copy link
Contributor Author

Could even be a fetchEvent.fromNavigate boolean

@annevk
Copy link
Member

annevk commented Jan 7, 2014

Maybe source or some such? I think we want to expose CSP types somewhere. E.g. img-src, script-src etc. This could fit into that.

@annevk
Copy link
Member

annevk commented Jan 7, 2014

Although that would really be part of the Request object.

@jakearchibald
Copy link
Contributor Author

Happy with request.source.

@jakearchibald
Copy link
Contributor Author

http://developer.chrome.com/extensions/webRequest.html#type-RequestFilter defines "main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", or "other". The naming is a little off (ew, underscores), but that kind of granularity could be useful.

@annevk
Copy link
Member

annevk commented Jan 8, 2014

I think we want to copy from CSP. Maybe not the names. There's sniffing context too which might be useful. The people in charge of networking would be good to help out here to know exactly what what is right.

@slightlyoff
Copy link
Contributor

Decisions from today's discussion:

  • type -> purpose
  • values for purpose are derived from CSP: connect, font, img, media, object, script, style, worker, popup, child, navigate
  • All of these types are exclusive
  • connect defines XHR, fetch, and other unspecified loads
  • popup, child, and navigate replace e.type and e.isTopLevel

Needs review from the CSP folks; /cc @abarth @mikewest

slightlyoff added a commit that referenced this issue Jan 24, 2014
Moves to use FetchEvent.purpose (etc.)

Refs #140
Refs #46
@devd
Copy link

devd commented Jan 24, 2014

Just as a contrast to the Chrome documentation: here's mozilla's nsiContentPolicy: https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIContentPolicy It defines a lot of possible request types.

I am not sure about using CSP. CSP does not aim to look at network requests: rather, it is about what content gets into the page. There are requests that CSP does not talk about (anchor, anchor ping, sendBeacon) and there are requests that CSP does talk that SW does not (form-action, as opposed to the broader "navigation" that SW talks about)

@annevk
Copy link
Member

annevk commented Jan 24, 2014

We want to expose the superset. While CSP is applied between the document and the service worker (in the fetch layer), passing through where the response will be used can be useful in deciding certain things. E.g. whether to be strict about content-type, what to do about fallback, etc.

@sicking
Copy link

sicking commented Jan 24, 2014

We also need to clarify if the fetch that happens when a (non-serviceworker) worker is being loaded. Does the fetch that happens to load the worker have .topLevel set to true? Is it considered a navigation? At the very least we should make it clear that it's a fetch of a main worker-script.

@annevk
Copy link
Member

annevk commented Jan 24, 2014

.purpose will return "worker" for that scenario.

@annevk
Copy link
Member

annevk commented Feb 5, 2014

See also http://wiki.whatwg.org/wiki/Contexts "context" seems like a name we could use here too rather than "purpose".

@annevk
Copy link
Member

annevk commented Jun 16, 2014

This is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants