Alex Daro Alex Daro - 6 months ago 50
C++ Question

Load HTML page after chrome.tabs.onCreated

I am trying to load a static HTML file after I have opened a new tab. This code will act as a Chrome extension. I am stuck in an infinite loop and don't know how to proceed.

Here is my manifest.json:

{
"manifest_version": 2,

"name": "Getting started example",
"description": "This extension shows a Google Image search result for the current page",
"version": "1.0",

"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Click here!"
},

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

"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}


Here is my background.js (chrome.tabs.create will result in an obvious endless loop):

chrome.tabs.onCreated.addListener(function(tab) {
// INSERT HTML HERE
// chrome.tabs.create({url: chrome.extension.getURL('mypage.html')});
});


How can I achieve this? Do I have to dynamically create the HTML in JavaScript? Or can I load a static HTML file?

Answer

Chrome extensions have an explicit option in the manifest for replacing certain pages, chrome_url_overrides.

For example:

"chrome_url_overrides": {
   "newtab": "mypage.html"
},