I am a new one for the extension. I want to open a chrome extension page programmatically. Eg:
chrome-extension://njlkegdphefeellhaongiopcfgcinikh/options.html
When I click the web page button or link I want to open the particular extension tab.
I tried many ways. Directly call using javascript and so many ways. But I couldn't find the proper solution. Anybody have any idea.
(My target is using JavaScript to open the extension tab)
I am a new one for the extension. I want to open a chrome extension page programmatically. Eg:
chrome-extension://njlkegdphefeellhaongiopcfgcinikh/options.html
When I click the web page button or link I want to open the particular extension tab.
I tried many ways. Directly call using javascript and so many ways. But I couldn't find the proper solution. Anybody have any idea.
(My target is using JavaScript to open the extension tab)
Share Improve this question edited Mar 31, 2014 at 13:48 Sachin Jain 21.8k34 gold badges110 silver badges176 bronze badges asked Mar 31, 2014 at 12:41 PuvanarajanPuvanarajan 2,9166 gold badges28 silver badges37 bronze badges 3- What errors or bad results are you getting? You need to be more specific in what you have tried. – abraham Commented Mar 31, 2014 at 20:10
- @abraham No errors. But no output :(. I tried href, and window.open and etc. – Puvanarajan Commented Apr 1, 2014 at 3:39
- Hi I don't need to create a new one but where as i want to reopen the same on the browser extension icon – ThinkTank Commented Jul 8, 2019 at 13:52
2 Answers
Reset to default 13Here is one of the solutions:
- Make sure your content script runs on the page on which you are clicking on the button.
When you click on button on web page, add event listener from content script and in the event listerner pass a messgae to background.
chrome.runtime.sendMessage({message: 'buttonClicked'}, function() { /* callback */ });
In your background script, listen to the message from content script.
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if (request.message == 'buttonClicked') { // Create a new tab with options page } });
To create a new tab with options.html page, you can do this
chrome.tabs.create({ active: true, url: 'options.html' }, null);
The web extension API includes a runtime.openOptionsPage()
method for just this purpose. To use it:
- You must have an options page defined.
- Call
browser.runtime.openOptionsPage()
(orchrome.runtime.openOptionsPage()
, depending on the browser you're working with) from your background script.
Though this message is ostensibly part of runtime
, it seems to only work correctly when called from a background script.
MDN docs are here.