browser_action on file:///

78 views
Skip to first unread message

Tyler

unread,
Mar 14, 2011, 3:47:34 PM3/14/11
to Chromium-extensions
Goal of my extension: User opens a local HTML file, pushes a button, I
inject jQuery into that local HTML file and do a bunch of formatting
of the page. Bigger picture, the local HTML file is a report with some
poor formatting and I just want to clean it up a bit. I started a
prototype where I simply inject jQuery and <div>hello world</div> into
a page which works fine for http:// files, but not local files.

I searched and found a number of posts, but no definitive response.
Just to be clear, I don't want my extension to be able to open files
on a user's file system as I understand the security implications that
has. I just want the user to open a local file, then push a button to
format it.

Thanks,
Tyler

Boris Smus

unread,
Mar 17, 2011, 7:11:14 PM3/17/11
to Tyler, Chromium-extensions
This should work. When I open a file:// URL, content scripts that have "matches": ["<all_urls>"] get injected as expected. Could you please share your manifest?

Thanks,
- 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.


Scott Fujan

unread,
Mar 17, 2011, 7:21:00 PM3/17/11
to Boris Smus, Tyler, Chromium-extensions
I have just come upon a similar issue where I can't use executeScript on a file:// url tab when the checkbox is checked. The contentscript works as expected. I use <all_urls> for both permissions and matches. Seems to be a bug, but I need to research more.

PhistucK

unread,
Mar 18, 2011, 7:30:15 AM3/18/11
to Scott Fujan, Boris Smus, Tyler, Chromium-extensions
When using executeScript, you need to specify "<all_urls>" in the permissions key.

PhistucK

Scott Fujan

unread,
Mar 18, 2011, 2:20:35 PM3/18/11
to PhistucK, Boris Smus, Tyler, Chromium-extensions
Actually, I just did the testing, and file:// is never enabled for permissions. I always get this message whether the file:// checkbox is checked or not:

"Error during tabs.executeScript: Cannot access contents of url "file:///test.htm". Extension manifest must request permission to access this host."

Additionally, I just found out that the file:// checkbox doesn't even appear if you only have <all_urls> in the permissions. You have to have a content script with <all_urls> for the checkbox to appear.

I have tested this in 12.0.705.0 and 10.0.648.134, and I have tested unpacked and packed versions. I am going to file a bug and post back here unless someone catches something stupid.

manifest.json:
{
  "name": "Test File://",
  "version": "0.1",
  "description": "descrip",
  "background_page": "background.html",
  "content_scripts": [
    {
      "matches": [ "<all_urls>" ],
      "js": [ "test.js" ]
    }
  ],
  "permissions": ["tabs", "<all_urls>"]
}

background.html:
<html><body><script>
chrome.windows.getAll({populate:true},function(wins){
  for(i in wins) for(j in wins[i].tabs) if(wins[i].tabs[j].url.match(/^file/))
    chrome.tabs.executeScript(wins[i].tabs[j].id,{code:"alert('test!')"});
});
</script></body></html>

Scott

unread,
Mar 18, 2011, 2:37:02 PM3/18/11
to Chromium-extensions
crbug.com/76705

On Mar 18, 1:20 pm, Scott Fujan <sc...@fujan.name> wrote:
> Actually, I just did the testing, and file:// is never enabled for
> permissions. I always get this message whether the file:// checkbox is
> checked or not:
>
> "Error during tabs.executeScript: Cannot access contents of url "
> file:///test.htm". Extension manifest must request permission to access this
> host."
>
> Additionally, I just found out that *the file:// checkbox doesn't even
> appear* if you only have <all_urls> in the permissions. You have to have a
> content script with <all_urls> for the checkbox to appear.
>
> I have tested this in 12.0.705.0 and 10.0.648.134, and I have tested
> unpacked and packed versions. I am going to file a bug and post back here
> unless someone catches something stupid.
>
> manifest.json:
> {
>   "name": "Test File://",
>   "version": "0.1",
>   "description": "descrip",
>   "background_page": "background.html",
>   "content_scripts": [
>     {
>       "matches": [ "<all_urls>" ],
>       "js": [ "test.js" ]
>     }
>   ],
>   "permissions": ["tabs", "<all_urls>"]
>
> }
>
> background.html:
> <html><body><script>
> chrome.windows.getAll({populate:true},function(wins){
>   for(i in wins) for(j in wins[i].tabs)
> if(wins[i].tabs[j].url.match(/^file/))
>     chrome.tabs.executeScript(wins[i].tabs[j].id,{code:"alert('test!')"});});
>
> </script></body></html>
>
>
>
>
>
>
>
> On Fri, Mar 18, 2011 at 6:30 AM, PhistucK <phist...@gmail.com> wrote:
> > When using executeScript, you need to specify "<all_urls>" in the
> > permissions key.
>
> > ☆*PhistucK*
>
> > On Fri, Mar 18, 2011 at 01:21, Scott Fujan <sc...@fujan.name> wrote:
>
> >> I have just come upon a similar issue where I can't use executeScript on a
> >> file:// url tab when the checkbox is checked. The contentscript works as
> >> expected. I use <all_urls> for both permissions and matches. Seems to be a
> >> bug, but I need to research more.
>
> >> On Thu, Mar 17, 2011 at 6:11 PM, Boris Smus <s...@chromium.org> wrote:
>
> >>> This should work. When I open a file:// URL, content scripts that have
> >>> "matches": ["<all_urls>"] get injected as expected. Could you please share
> >>> your manifest?
>
> >>> Thanks,
> >>> - Boris
>
> >>> On Mon, Mar 14, 2011 at 12:47 PM, Tyler <tyler.m...@gmail.com> wrote:
>
> >>>> Goal of my extension: User opens a local HTML file, pushes a button, I
> >>>> inject jQuery into that local HTML file and do a bunch of formatting
> >>>> of the page. Bigger picture, the local HTML file is a report with some
> >>>> poor formatting and I just want to clean it up a bit. I started a
> >>>> prototype where I simply inject jQuery and <div>hello world</div> into
> >>>> a page which works fine for http:// files, but not local files.
>
> >>>> I searched and found a number of posts, but no definitive response.
> >>>> Just to be clear, I don't want my extension to be able to open files
> >>>> on a user's file system as I understand the security implications that
> >>>> has. I just want the user to open a local file, then push a button to
> >>>> format it.
>
> >>>> Thanks,
> >>>> Tyler
>
> >>>> --
> >>>> You received this message because you are subscribed to the Google
> >>>> Groups "Chromium-extensions" group.
> >>>> To post to this group, send email to chromium-extensi...@chromium.org.
> >>>> To unsubscribe from this group, send email to
> >>>> chromium-extensions+unsubscr...@chromium.org.
> >>>> For more options, visit this group at
> >>>>http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en
> >>>> .
>
> >>>  --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "Chromium-extensions" group.
> >>> To post to this group, send email to chromium-extensi...@chromium.org.
> >>> To unsubscribe from this group, send email to
> >>> chromium-extensions+unsubscr...@chromium.org.
> >>> For more options, visit this group at
> >>>http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en
> >>> .
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Chromium-extensions" group.
> >> To post to this group, send email to chromium-extensi...@chromium.org.
> >> To unsubscribe from this group, send email to
> >> chromium-extensions+unsubscr...@chromium.org.
Reply all
Reply to author
Forward
0 new messages