Yes, content scripts can use only part of the webextensions API: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#WebExtension_API
But you can use browser.runtime.sendMessage
to send message to your background script (which can open the window and return tabId
.
Know that message send with browser.runtime.sendMessage
will be received by all parts of your addon, including your new window.
However if you want to target only the new window, you should use browser.tabs.sendMessage
and use the tabId
returned by browser.windows.create
. Again you can do this only from background script. So if you want to use it from your content script, you need to forward the message through background script, for example:
browser.runtime.onMessage.addListener((data, sender) => {
switch (data.type) {
// return promise that will resolve to whatever the target tab replies (again by returning a promise)
case 'forwardToTab': return browser.tabs.sendMessage(data.targetTabId, data.customData);
}
});