tab.openerTabId undefined in Firefox WebExtension

≡放荡痞女 提交于 2019-12-12 03:44:34

问题


I have this code in background script of my Firefox WebExtension, but it prints : "OPENER ID: undefined" each time new tab is created:

chrome.tabs.onCreated.addListener(function (tab) {
    console.log("OPENER ID: " + tab.openerTabId);
});

What is the problem? This code works well in Chrome, and in documentation it says that openerTabId property is supported in Firefox.

And yes, openerTab is still present when new tab is created (new tab is created by clicking on some link in openerTab).


回答1:


The problem is that Firefox does not support tabs.Tab.openerTabId. The compatibility notes for Firefox explicitly state [emphasis mine]:

'openerTabId' is not supported.

If you really need this information, you can, mostly, track it yourself using various events: How to get openerTabId in Firefox WebExtensions?

If this is functionality you desire to see as part of the WebExtensions API, I suggest you file a bug to track its implementation.




回答2:


First, I believe Firefox uses

browser.tabs.onCreated.addListener(function(tab) {});

rather than

chrome.tabs.onCreated.addListener(function(tab) {});

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities

I do not think that is what your main problem is though, since I have been trying to replicate the issue and I too am seeing that it does not seem to be possible for a background script to access the openerTabId property (at least from a background script activated by clicking on a browser icon). I can access other Tabs.tab properties, such as status, index, and id, but NOT the openerTabId property. openerTabID keeps reading as "undefined". I do not know whether it is necessary to take special steps to be able to access this property, versus whether this a bug (a bug since the documentation says it should be readable, so long as the tab that called the opening still exists). https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab

It would be very helpful if you would provide more details about how your coding logic looks (what does the manifest look like?, etc), so that maybe more experienced contributors will weigh in.

(I am posting this here as an answer rather than as a comment because I do not yet have enough reputation to be able to comment.)



来源:https://stackoverflow.com/questions/41315422/tab-openertabid-undefined-in-firefox-webextension

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