How to inject into a local page (e.g. data:// or chrome-extension://) via a content script???

1,414 views
Skip to first unread message

MV-Dev

unread,
Jun 17, 2015, 6:53:49 PM6/17/15
to chromium-...@chromium.org
4 years ago I gave up I trying to figure out a way to inject content script into a local page, either a data url () or a local page inside my extension via chrome-extension://...

The problem is that I can't seem to find a way to have permission to work with dataurls in the same way as http:// or https://.

Maybe it's possible now?


I would like to load some page specified like this...
  • data:text/html,<h1>Hello!<%2Fh1>
    or
  • chrome-extension://jdfsadjlfkadlfkjasfkj/page1.htm
then catch the page "load" to inject content script like this...

    chrome.tabs.executeScript(nTabId, { file: "file1.js" }, function ()
   
{
        chrome
.tabs.executeScript(nTabId, { file: "file2.js" }, function ()
       
...

but I get an error like...

Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "chrome-extension://
dfphddhabbmcnjlpimiagbcgnanmpboi/page1.htm". Extension manifest must request permission to access this host.
    at Object...............


I have played with putting every permission under the sun into my manifest.json...

  "content_security_policy": "script-src 'self'; object-src 'self'",

 
"permissions": [
   
"tabs",
   
"notifications",
   
"<all_urls>",
   
"*://*/*"
 
]

and I have also tried DataURL (RFC 2397)

Use cases include making a local options page where I can get and set attributes OR being able to add an iframe and load a page from some site without running into cross-site scripting issues.

(It is possible to do this in Firefox.)

Maybe there's a another way?


As I am writing this I had another thought:  what if I created a file containing the full page locally then loaded it from here -- I'd at least get around the need for injection (in theory) then I'd only need to send messages to the browser.  Of course without having any content script to receive the messages.....   Oh well.
Reply all
Reply to author
Forward
0 new messages