Migrating chrome extension to web extension

☆樱花仙子☆ 提交于 2019-12-20 06:36:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!