sveltejs / svelte-devtools

A browser extension to inspect Svelte application by extending your browser devtools capabilities
https://chromewebstore.google.com/detail/svelte-devtools/kfidecgcdjjfpeckbblhmfkhmlgecoff
MIT License
1.48k stars 79 forks source link

Content script injection logic does not handle the case of multiple simultanious DevTools instances #59

Closed bershanskiy closed 1 year ago

bershanskiy commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

In src/background.js the handler for tabs.onUpdated event attachScript is added and removed without consideration for case of multiple simultanious DevTools instaces.

To Reproduce Steps to reproduce the behavior:

  1. Open tab 1 made with Svelte, open Svelte DevTools
  2. Open tab 2 example.com (or any other site), open Svelte DevTools, close Svelte DevTools
  3. Go to tab 1 and refresh page in any way (via F5 or CTRL+F5 shortcut, reload button, or Svelte DevTools)
  4. Notice that tad 1 Svelte DevTools window still shows "Not working? Did you..." message.

Expected behavior Tab 1 Svelte DevTools should work and not show "Not working? Did you..." message.

Environment

Additional context This issue is caused by improper port disconnect handling logic in background. It removes tabs.onUpdated event listener when tab 2 DevTools are closed at step 2, even though this listener is still needed for tab 1 DevTools at step 3 and 4. This bug can be easily fixed by taking into account number of open ports, e.g. by adding an extra counter or just checking toolsPorts.size. I won't file a PR for this because I'm changing background logic in a larger way which will fix this bug.