Closed Bug 1426434 Opened 8 years ago Closed 8 years ago

"data:text/html" as url in browser.tabs.create and browser.windows.create

Categories

(WebExtensions :: General, defect, P3)

59 Branch
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1317166

People

(Reporter: limkokhole, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0 Build ID: 20171118211007 Steps to reproduce: [1] Download the example code at https://github.com/mdn/webextensions-examples/tree/master/open-my-page-button [2] Modify "background.js", replace the `browser.tabs.create`'s url part to "data:text/html", e.g.: browser.tabs.create({ //"url": "/my-page.html" "url": "data:text/html,<!DOCTYPE html><html><body><p>hello</p></body></html>" }); [3] You may also add this: browser.windows.create({ type: "panel", url: "data:text/html,<!DOCTYPE html><html><body><p>hello</p></body></html>" }); [4] `web-ext run` to load the extension. [5] Open "about:debugging" -> under "open-my-page" extension -> click "debug" link -> open "browser console" [6] Click the toolbar browser action icon. Actual results: Nothing happen. Browser console shows this errors: Type error for parameter createData (Error processing url: Value "data:text/html,<!DOCTYPE html><html><body><p>hello</p></body></html>" must either: match the format "relativeUrl", or be an array value) for windows.create. background.js:12 Error: Illegal URL: data:text/html,<!DOCTYPE html><html><body><p>hello</p></body></html> undefined TypeError: setting getter-only property "maxRows" Expected results: Display "hello" in new tab and new window. Note that Chromium web browser can treat "data:text/html" as url without issue . Simply replace "browser" to "chrome" in "background.js" and load it in Chromium to test. Attached is the screenshot to compare Firefox (top window) VS Chromium (bottom window).
Component: General → WebExtensions: General
I note that we have been locking down on the use of data: URLs in Firefox as per: https://blog.mozilla.org/security/2017/11/27/blocking-top-level-navigations-data-urls-firefox-58/ I'm not sure why we'd want to allow this. Can you provide a use case that makes sense? Also cc'ing Christoph on this.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(limkokhole)
Priority: -- → P3
Summary: WebExtensions API - "data:text/html" as url in browser.tabs.create and browser.windows.create → "data:text/html" as url in browser.tabs.create and browser.windows.create
devtools_page js collect network traffic list -> user click one of the list to see post data in pop up window -> devtools_page js passs data to background page -> background page calls `browser.windows.create({url: data:text/html<post data html>})` -> direct show the post data page in popup window. But I realized that I can use message passing to achieve what I want: devtools_page js collect network traffic list -> user click one of the list to see post data in pop up window -> devtools_page js passs data to background page -> background page calls `browser.windows.create({url: extension local popup.html})` -> popup.html include popup.js -> popup.js calls `browser.runtime.onMessage.addListener()` to add message listener -> popup.js calls `browser.runtime.sendMessage()` to background page to inform listener setup done -> background page calls `browser.tabs.sendMessage(<post data>)` -> popup.js received and shows data in popup.html. Not only this make code complicated for simple task, it also has one minor problem, i.e. browser.windows.create() not able to pass custom unique id to popup window html, so it might surprising user (but acceptable IMHO) if 2 windows popup in order but shows the wrong item: [1] user click item A -> background page push item A to array , calls `browser.windows.create` -> popup.js hang(set some timeout to test) -> ... [2] Then user click item B -> background page push item B to array , then calls `browser.windows.create` -> popup.js done -> popup.js send message to background page -> background send item A pop from pending array since it has no way to know the message is tied to window clicked from which item -> user surprise why item B's popup window shows item A. The only concerns is `data:text/html` might hit the maximum number of strings allowed. So I prefer message passing instead of "data:text/html", and the wrong window scenario is acceptable in my case, but I'm not sure other people case though. And for compatibility reason, I wonder people may has issue to transfer the extension from Chrome to Firefox since chrome is support "data:text/html". It's not really important to fix, sorry for disturb.
Flags: needinfo?(limkokhole)
Product: Toolkit → WebExtensions
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: