XMLHttpRequest for chrome-extension protocol

1,669 views
Skip to first unread message

Marek Sebera

unread,
Oct 21, 2011, 8:38:29 AM10/21/11
to Chromium-extensions
Hi,
I'm using background page and I need to inject some code into current
tab contents.

so I do following:

-> define browser_action
-> define listener like this
chrome.browserAction.onClicked.addListener
-> calling script loaded by content_scripts via
chrome.tabs.executeScript

And from page content I need to load html resource from within
extensions folder.

but using this XMLHttpRequest gives me error Cross origin requests are
only supported for HTTP

handled by XMLHttpRequest by error NETWORK_ERR: XMLHttpRequest
Exception 101

Note: address is like chrome-extension://someextensionid/file.html

So how am I supposed to solve it? How can I load local extension
resources from files?

Boris Smus

unread,
Oct 21, 2011, 9:58:20 PM10/21/11
to Marek Sebera, Chromium-extensions
Hey Marek,

Take a look at http://code.google.com/chrome/extensions/xhr.html. Basically you need host permissions.

- Boris


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.




--
Ask your next question on Stack Overflow, using the google-chrome-extension tag.

Gildas

unread,
Oct 23, 2011, 5:26:41 AM10/23/11
to Chromium-extensions
On 22 oct, 03:58, Boris Smus <s...@chromium.org> wrote:
> Hey Marek,
>
> Take a look athttp://code.google.com/chrome/extensions/xhr.html. Basically
> you need host permissions.
>
> - Boris

Really ?

I'm pretty sure this sentence says the opposite:
"Without requesting additional privileges, the extension can use
XMLHttpRequest to get resources within its installation."

Boris Smus

unread,
Oct 23, 2011, 10:07:02 PM10/23/11
to Gildas, Chromium-extensions
Apologies, I completely misread your question. Please defer to Mihai's answer :)

- Boris

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.

Paolo Casaschi

unread,
Oct 24, 2011, 6:52:13 AM10/24/11
to Chromium-extensions
> I'm pretty sure this sentence says the opposite:
> "Without requesting additional privileges, the extension can use
> XMLHttpRequest to get resources within its installation."

It works like that for my extension. I can access chrome-extension://
my-extension-id/* files using XMLHttpRequest without asking for any
explicit permissions.
And in the latest canary/development versions I also see with the
webRequest API all network transactions involving chrome-extension://
my-extension-id/* URLs
Reply all
Reply to author
Forward
0 new messages