2

I have a problem with communication based on browser.runtime.connect between a content script and a background script of my test echo extension. I have published my code and extension package on github.

Short description of this extension. You can run the extension on this GitHub test page. The content script connects to the background script using browser.runtime.connect and sends a message via browser.runtime.Port object when “Submit” button is clicked. The background script receives the message, converts it to upper case and sends back. Then content script receives the modified message and displays it on the page (received message field).

This extension works fine when I add it to Edge using Load extension button as described in the Microsoft Edge documentation. So if you open the test page with the loaded extension you should see “HELLO FROM BACKGROUND SCRIPT” text in the received message field.

But there is a strange problem if this extension is installed from a package… The extension doesn’t work until I open the background page of this extension and reload the test page… So you can try to reproduce it:

  1. Install this extension from the package
  2. Open the test page. The background script doesn’t work properly (received message field is empty) and this script doesn’t receive sent messages… Page reloading or turning off\on of the extension doesn’t help.
  3. Open background page of this extension. Then this page may be closed.
  4. Reload the test page
  5. Extension starts to work properly…

Note: this test extension is based on the runtime.connect example published on MDN (sorry, but I can not insert more than two links...).

Could you help me to solve this problem? Maybe I missed something in the documentation...

  • I also hit this issue ever, for appx packages, the background page doesn't load until you manually inspect it. It's encouraged to raise a bug here https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/ – Haibara Ai May 31 '17 at 02:19
  • @HaibaraAi thanks for your comment. Now I know that other developers have the same problem. I raised the bug four days ago https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12156180/ But I still have not received a response... It seems that this process isn't fast. Could you mark this bug as reproducable? I mean, could you push **Me too** button? Maybe this will help to speed up this bug report processing... – Alexey Sidorov May 31 '17 at 03:22
  • Thanks for raising the bug! I upvoted that : ) – Haibara Ai May 31 '17 at 03:38

1 Answers1

1

This is by design since your extension manifest specified persistent flag as false. On Microsoft Edge, the default behavior for background script is non-persistent.

Chee Chen
  • 37
  • 2
  • Thank you for the answer! I have set the persistent property value to true, so the extension works properly now even if it is installed from a package. But still... what is the correct way to load a non-persistent background page? For example on Google Chrome, this page will be loaded once for each new version of your extension. After that it will only be loaded to deliver events you have registered for ([the documentation](https://developer.chrome.com/extensions/event_pages)). – Alexey Sidorov Jun 08 '17 at 04:36