So what you call “popup” is actually a normal tab, right?
Also the browser.tabs.query({ active: true, currentWindow: true }) can be replaced with: browser.tabs.getCurrent()
Now regarding ports - I’m not very good with these, so instead I would use messaging.
- when your popup script runs, just send message to your background script with:
const arrayData = await browser.runtime.sendMessage({type: 'get_array'});
- in your background script:
browser.runtime.onMessage.addListener(data => {
if (data.type === 'get_array') return Promise.resolve([1, 2, 3, 4]);
});
And that’s it. When you return promise from the message handler, the value will be send back to the sender.
See the docs for more info: