How to reload certain tab in chrome extension

I am trying to reload a page that a user may have open in one of their tabs from popup (specifically popup.js). I am looking at this answer but it is only for the current tab https://stackoverflow.com/a/25246060/8786209.

Also when it runs I get this error:

popup.html:1 Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "thewebpageiamtryingtoaccess.com".
Extension manifest must request permission to access this host at Object.callback (chrome-extension://mjckbfpnokoplldjpijdfhffbbbfflah/popup.js:3:17)

I have added

"permissions": [
    "tabs"
  ],

inside my manifest, still no luck. How would I be able to do it for a specific tab that the user has open. I want this to reload the website the first time the extension is loaded so the the user does not have to reload the webpage manually to have the content script take effect. Thanks!

Answers:

Answer

For fixing execute error you need to change permissions in your manifest file to:

  "permissions": [
     "tabs",
     "http://*/",
     "https://*/"
  ]

You can query ID of the tab by url like this:

chrome.tabs.query({url: "http://thewebpageiamtryingtoaccess.com/*"}, function(tab) {
   // reload tab with one of the methods from linked answer
   chrome.tabs.reload(tab[0].id) 
})

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.