问题
I have been migrating my extension from chrome to web extension. Link of chrome extension is here
Everything worked except I need tab information inside my angular application, there I am getting an error as TypeError: "browser.tabs is undefined"
I can access the tab info inside background script and I can send that to the content script but not in the main application.
My application opens in iframe, iframe points to the angular application.
browser.tabs.getCurrent(function (tabs) {
//these are tabs
});
I was able to get it in chrome extension , I can;t find a way to send it from background or content to main app.
I get it in background and send it to content
BACKGROUND.js
browser.tabs.query({ currentWindow: true, active: true }, function (tabs) {
tabs = tabs
chrome.tabs.sendMessage(tabs[0].id, { action: "tabs", tabs : tabs }, function(response) {
console.log(response);
});
});
Getting in content as
CONTENT.JS
browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action == 'tabs') {
tabs = request.tabs;
}
if (request.action == 'get_tabs') {
sendResponse(tabs);
}
});
Also trying to get it in main app by sending message and response back like in get_tabs
In main app somewhere
browser.runtime.sendMessage({ 'action': 'get_tabs' }, function (tabs) {});
If you have faced this please answer.
来源:https://stackoverflow.com/questions/51897510/migrating-chrome-extension-to-web-extension