0

I'm trying to develop a chrome extension that will capture screenshots without user intervention and push them to a server. I do not intend to publish this extension, I just want to develop it for me. I would feed the extension with a list of urls to visit on a daily base and then capture screenshots and send them to a server.

I'm already stuck by a permission problem at the very beginning. Here is the code in background.js:

chrome.tabs.create({ url: 'https://www.example.com', active: true }, tab => 
{
    if (chrome.runtime.lastError) 
        {
            console.error(chrome.runtime.lastError);
        } 
    else 
        {
            console.log(tab);
            
            chrome.tabs.captureVisibleTab(null, {format: 'png'}, function(dataURI) 
              {
                // do something
              });
       }
 });

When running this code, I get the following error: Unchecked runtime.lastError: Cannot access contents of url "". Extension manifest must request permission to access this host.

In my manifest, I have:

"host_permissions":
[
    "tabs",
    "*://*/",
    "http://*/",
    "https://*/",
    "<all_urls>",
    "notifications",
    "webRequest",
    "webNavigation",
    "management",
    "storage",
    "webRequestBlocking",
    "http://*/*",
    "background",
    "alarms",
    "desktopCapture",
    "activeTab",
    "https://*/*"

],

"permissions": [
    "tabs",
    "http://*/",
    "https://*/",
    "<all_urls>",
    "notifications",
    "webRequest",
    "webNavigation",
    "management",
    "storage",
    "webRequestBlocking",
    "http://*/*",
    "background",
    "alarms",
    "desktopCapture",
    "activeTab",
    "https://*/*"

],


 "background": {
"scripts": ["background.js"],
"persistent": true
  },

"content_scripts": [
    {
        "matches": ["http://*/*", "https://*/*"],
        "js": ["content.js"]

    }],

"browser_action": {
    "default_icon": "logo.png",
    "default_popup": "popup.html"
    }

There are multiple discussions about this topic on stackexchange, I have applied recommendations about permissions but it still doesn't work.

Where am I missing something?

Thanks

Laurent

Laurent
  • 1,465
  • 2
  • 18
  • 41
  • 1
    The tab hasn't even started loading in the callback of create() so it doesn't have a `url` and no content. You should wait for the tab to load, [example](https://stackoverflow.com/a/44864966). – wOxxOm Jan 10 '23 at 15:21
  • @wOxxOm ah yes, it was so obvious :) Thanks for your help, it works perfectly now! – Laurent Jan 10 '23 at 17:34

0 Answers0