Question: I want open all the links on a web page with a single click on Chrome Extensions. I try for that وbut I did not get any results. please help me ...

my manifist.json file :

```
{
  "name": "Open Links in New Tabs",
  "version": "1.0",
  "description": "open all link in page on new tabs with one click",
  "background_page" : "background.html",
  "browser_action": {
    "default_icon": "icon.png"
  },

  "permissions": 
     ["tabs"],
  "manifest_version": 2
}

```

background.html file :

```
<!doctype html>
<html>
  <head>
    <script src="background.js"></script>
  </head>
  <body>
  </body>
</html>

```

background.js file :

```
for(i = 0; i < document.links.length; i++) 
{ chrome.tabs.create({active: true, url: document.links[i].href});}

```

Please explain any problems. thanks

Answer: 
When you access the `document` object in `background.js`, you're looking at background page, not the currently active tab.

To access the DOM contents of the open page, you will need a content script. It can then send a message to the background script (which has access to `chrome.tabs`) with the list of links to open.

Please take a moment to read this excellent [overview of extension architecture](https://developer.chrome.com/extensions/overview#arch). Also, read on [messaging](https://developer.chrome.com/extensions/messaging) to pass the list.

Actually, if you're going to be injecting the script programmatically via `chrome.tabs.executeScript`, you can ditch messaging and just use the [callback of `executeScript`](https://developer.chrome.com/extensions/tabs#method-executeScript).

---

As a side note, since you don't have any HTML in the background page, you can replace it with an auto-generated script page like this:

manifest.json

```
"background": {
   scripts": ["background.js"]
},

```

in place of `"background_page"`

---

Lastly, consider minimal permissions that you need.

If your extension is supposed to trigger on click on the extension button (wrapped in a `chrome.browserAction.onClicked` listener), you can inject a script "for free" with [`activeTab` permission](https://developer.chrome.com/extensions/activeTab), no need for tabs/host pemission.

Same goes to `chrome.tabs.create`, you don't need the mighty and scary "tabs" permission.
There are quite a few.

1. A background script doesn't have access to the page DOM of a tab. The only DOM it can access directly is the DOM of the background.html. You should use a content script and message passing.
2. `background_page` is an option of Manifest Version 1, you are using Manifest Version 2, for which the option is called `background`. Usually you provide the `background.js` directly as a script (see <https://developer.chrome.com/extensions/background_pages>). You should return after you implemented those suggestions