worker-dom icon indicating copy to clipboard operation
worker-dom copied to clipboard

[Feature request] Document.location and Window.location

Open Tofandel opened this issue 3 years ago • 12 comments

It would be nice to support the Document.location api to be able to use Vue-Router (or other js framework routers) in web workers

Tofandel avatar Jun 19 '21 13:06 Tofandel

+1 for document.location and window.location, see the similar issue #8.

niutech avatar Jul 01 '21 10:07 niutech

As written by @choumx in https://github.com/ampproject/worker-dom/issues/8#issuecomment-514409113

window.location.search is no longer undefined but it returns WorkerLocation.search which is not the expected value. We'll need to hydrate this from the main thread for read access. Writing is another matter.

In order to support these features we'll need to hydrate the values from the main thread as well as keep it in sync as the Location is updated over time. Writing to the property would require creating a new command/processor for worker-->main-thread communication.

This is a great FR, but unfortunately worker-dom isn't heavily staffed right now. I can't dedicate the time to implementing this now, but would be more than happy to review a PR and guide an implementer in the right direction.

samouri avatar Jul 12 '21 13:07 samouri

For a PR to get through how much of the Location API would need to be built out?

For example a read only version of the API, supporting only some the values?

NicholasKao1029 avatar Jul 12 '21 16:07 NicholasKao1029

@NicholasKao1029: in general we implement features on a need basis, since each feature we add has a cost in terms of bundle size.

A partial readonly API works for me.

cc @kristoferbaxter

samouri avatar Jul 12 '21 18:07 samouri

A readonly API to start works for me, so long as it is very clearly documented and has tests.

kristoferbaxter avatar Jul 12 '21 19:07 kristoferbaxter

I made the first draft of document.location support (PR #1075), but I don't know how to properly transfer the Location object between the main thread and worker, so it is not complete. But could @samouri or @kristoferbaxter have a look at this and maybe pick up the work? Thanks.

niutech avatar Jul 12 '21 20:07 niutech

@niutech could I work on your PR with you?

NicholasKao1029 avatar Jul 13 '21 16:07 NicholasKao1029

@NicholasKao1029 Sure! That's what I was hoping for. You can pull my branch https://github.com/niutech/worker-dom/tree/location

niutech avatar Jul 13 '21 18:07 niutech

I see some work on this has begun, but I'd like to add my support to the original request. It would be very helpful in reconstructing the AMP CORS requirements for security on amp-script Fetch API calls.

AaronMLB avatar Aug 10 '21 13:08 AaronMLB

This may need an origin policy when trying to assign a new value to the location.

cometkim avatar Dec 21 '21 02:12 cometkim

any update?

surya0796 avatar Jan 29 '23 05:01 surya0796

No, I have abandoned my work due to the lack of time.

niutech avatar Jan 29 '23 08:01 niutech