Expose fetch to the worker debugger

NEW
Unassigned

Status

P3
normal
3 years ago
5 months ago

People

(Reporter: ejpbruel, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

3 years ago
The worker debugger needs a way to fetch URLs, but at the moment doesn't have an API available for this. To work around this, we use a rpc mechanism to request the main thread to fetch the URL on our behalf.

As it turns out, the fetch API is available in workers, and provides exactly the same functionality, so we should use that instead of duplicating it on the JS side.

The only thing that was preventing us from using it in the worker debugger was that DOM promises did not work together well with nested event loops, but this looks like it will be fixed soon: https://bugzilla.mozilla.org/show_bug.cgi?id=1229769
(Reporter)

Comment 1

3 years ago
Created attachment 8725634 [details] [diff] [review]
WIP

Here's a work in progress patch that exposes fetch to the worker debugger. I just have one problem: I can't figure out how to turn WorkerDebuggerGlobalScope.fetch_text.txt into a valid URL. Apparently using a relative URL doesn't work, and I obviously can't use a chrome URL either.

I can never remember what's the correct way to do this in a mochitest. Kyle, any help?
Attachment #8725634 - Flags: feedback?(khuey)
(In reply to Eddy Bruel [:ejpbruel] from comment #1)
> Created attachment 8725634 [details] [diff] [review]
> WIP
> 
> Here's a work in progress patch that exposes fetch to the worker debugger. I
> just have one problem: I can't figure out how to turn
> WorkerDebuggerGlobalScope.fetch_text.txt into a valid URL. Apparently using
> a relative URL doesn't work, and I obviously can't use a chrome URL either.
> 
> I can never remember what's the correct way to do this in a mochitest. Kyle,
> any help?

Can you just fetch the current script with "#"?
Comment on attachment 8725634 [details] [diff] [review]
WIP

Review of attachment 8725634 [details] [diff] [review]:
-----------------------------------------------------------------

Does this actually work?  I would expect Fetch events to go in the regular runnable queue, not the debugger queue, and thus not work ...
Attachment #8725634 - Flags: feedback?(khuey)
Flags: needinfo?(ejpbruel)
(Reporter)

Comment 4

3 years ago
(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #3)
> Comment on attachment 8725634 [details] [diff] [review]
> WIP
> 
> Review of attachment 8725634 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Does this actually work?  I would expect Fetch events to go in the regular
> runnable queue, not the debugger queue, and thus not work ...

I could be wrong, but as far as I can tell, the actual fetch happens on the main thread, and we use a promise proxy in the worker to make sure that the promise returned by the call to fetch in the worker is resolved when the fetch completes on the main thread. Assuming that promise is the only runnable involved, this *should* work, provided bug 1229769 lands.

It's very possible that I'm missing something though, since I'm not intimately familiar with the internals of fetch. This definitely needs tests.
Flags: needinfo?(ejpbruel)
(Reporter)

Updated

2 years ago
Assignee: ejpbruel → nobody

Updated

5 months ago
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.