Need a way to load scripts into a blank page and give it a URL

RESOLVED FIXED in Firefox 42

Status

()

Firefox
Extension Compatibility
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: billm, Assigned: Bobby Holley (parental leave - send mail for anything urgent))

Tracking

(Blocks: 1 bug)

34 Branch
Firefox 42
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox42 fixed)

Details

Attachments

(1 attachment)

(Reporter)

Description

2 years ago
The main way you load code into a Chrome extension is by specifying a "background page". This is a web page that's loaded into a hidden window. It has access to the extension APIs. The manifest file specifies either an HTML file or a list of scripts to load into the page.

Right now, if the list of scripts is provided, we call docShell.createAboutBlankContentViewer and then use createElement to create a bunch of <script> tags and append them to the document.

The problem with this approach is that the resulting document's URL is about:blank. Background pages often do XHRs, and the URL they provide is often a relative URL. We get an error from these XHRs. Chrome solves this by giving the background page a dummy URL (I think it's something like chrome-extension://foo/_generatedBackground.html). That way, relative URLs for XHRs are resolved relative to chrome-extension://foo/.

Bobby, how do you think we could solve this?
Flags: needinfo?(bobbyholley)
How s an XHR URI relative to chrome-extension:// foo useful, exactly?

Regardless, it seems like the addon code could just create a moz-extension substitution from foo/_generatedBackground.html to about:blank. Wouldn't that solve the problem?
Flags: needinfo?(bobbyholley)
(Reporter)

Comment 2

2 years ago
(In reply to (PTO July 22 - July 26) from comment #1)
> Regardless, it seems like the addon code could just create a moz-extension
> substitution from foo/_generatedBackground.html to about:blank. Wouldn't
> that solve the problem?

This sounds like a good idea!
Status: NEW → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → WORKSFORME
(Reporter)

Comment 3

2 years ago
Actually, I don't think that will work. You can only substitute based on the host rather than the entire URL.

I still like the idea of routing to about:blank, but I'm not sure how to do it. We could maybe use a different host for the background page, but that's pretty ugly and it might break some assumptions that extensions make.

Bobby, what do you think of adding support to SubstitutingProtocolHandler so that certain paths can have different mappings? It looks like net_ResolveRelativePath would be useful for this.
Status: RESOLVED → REOPENED
Flags: needinfo?(bobbyholley)
Resolution: WORKSFORME → ---
I think generalizing this stuff to do some sort of most-exact-matching is going to make it a lot more complicated. I think we can just hack something up to solve this problem in C++. I'll attach a patch shortly.
Created attachment 8640233 [details] [diff] [review]
Implement an about:blank page inside of moz-extension. v1
Flags: needinfo?(bobbyholley)
Attachment #8640233 - Flags: review?(wmccloskey)
(Reporter)

Comment 6

2 years ago
Comment on attachment 8640233 [details] [diff] [review]
Implement an about:blank page inside of moz-extension. v1

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

Yeah, this seems good. We might want to change the _blank.html name at some point, but this is fine for now.
Attachment #8640233 - Flags: review?(wmccloskey) → review+

Comment 7

2 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/237e7aac9def
https://hg.mozilla.org/mozilla-central/rev/237e7aac9def
Assignee: nobody → bobbyholley
Status: REOPENED → RESOLVED
Last Resolved: 2 years ago2 years ago
status-firefox42: --- → fixed
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → Firefox 42
You need to log in before you can comment on or make changes to this bug.