Port communication between background script and popup script

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.

  1. when your popup script runs, just send message to your background script with:
const arrayData = await browser.runtime.sendMessage({type: 'get_array'});
  1. 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: