I've been trying to look around the web and have had difficulties finding an answer. I've seen a couple of web extensions such as OneTab that open a local index.html
page when you click the browser action
button. Does anyone know how I can get my chrome extension
to open an index.html page when browser action
is pressed?
There are two ways to open your local HTML page by a browser action.
manifest.json
"browser_action": {
"default_icon" : "128.png",
"default_popup" : "localPage.html",
"default_title" : "localPage title"
}
manifest.json
"background": {
"scripts": ["background.js"]
},
background.js
chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.create({ url: chrome.runtime.getURL("localpage.html") });
});
You should take a look at chrome.browserAction and chrome.runtime.getURL.
manifest.json
{
"name": "Your Extension Name",
"description": "Your Extension Description",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"title": "Your Browser Action Name"
}
}
background.js
chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.create({ url: chrome.runtime.getURL("index.html") });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With