Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEX:when send message from background to Quasar App, the relative event was triggered not once but many times #14778

Open
heavenkiller2018 opened this issue Nov 2, 2022 · 3 comments
Labels
bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite kind/bug 🐞 mode/bex Qv2 🔝 Quasar v2 issues

Comments

@heavenkiller2018
Copy link

What happened?

I followed this instruction to check the communication from background script to Quasar App

[Background Script | Quasar Framework](https://quasar.dev/quasar-cli-vite/developing-browser-extensions/background-script)

background.ts

export default bexBackground((bridge, allActiveConnections) => {
    chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
    bridge.send('bex.tab.opened', { url: tab.url });
  });

}

Quasar App (as iframe form to show on common web page)

function doOnTabOpened(url) {
  console.log('New Browser Tab Openend: 🎯', url)
}

// Add our listener
$q.bex.on('bex.tab.opened', doOnTabOpened)

// Don't forget to clean it up
onBeforeUnmount(() => {
  $q.bex.off('bex.tab.opened', doOnTabOpened)
})

then I run these code, I found the event bex.tab.opened which should be triggered only once was triggered many times when I opened a new tab.

image

What did you expect to happen?

only be triggered once.

Reproduction URL

https://stackblitz.com/edit/quasarframework-vfcnwa

How to reproduce?

.

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

BEX Mode

Platforms/Browsers

Chrome

Quasar info output

❯ quasar info

Operating System - Linux(5.15.0-50-generic) - linux/x64
NodeJs - 18.12.0

Global packages
  NPM - 8.19.2
  yarn - 1.22.19
  @quasar/cli - 1.3.2
  @quasar/icongenie - Not installed
  cordova - Not installed

Important local packages
  quasar - 2.10.1 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-vite - 1.1.3 -- Quasar Framework App CLI with Vite
  @quasar/extras - 1.15.5 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.2.41 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.1.6
  pinia - 2.0.23 -- Intuitive, type safe and flexible Store for Vue
  vuex - Not installed
  vite - 2.9.15 -- Native-ESM powered web dev build tool
  eslint - 8.26.0 -- An AST-based pattern checker for JavaScript.
  electron - Not installed
  electron-packager - Not installed
  electron-builder - Not installed
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  @capacitor/core - Not installed
  @capacitor/cli - Not installed
  @capacitor/android - Not installed
  @capacitor/ios - Not installed

Quasar App Extensions
  *None installed*

Networking
  Host - ubuntu
  enp1s0 - 192.168.8.101
  docker0 - 172.17.0.1

Relevant log output

No response

Additional context

No response

@github-actions github-actions bot added bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite mode/bex labels Nov 2, 2022
@pbkompasz
Copy link
Contributor

Try

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
    if (changeInfo.url) {
      bridge.send('browserTabUpdated', { tab, changeInfo })
    }
  })

@captainjapeng
Copy link

Hi! I'm also experiencing this issue, it seems that bexBackground's callback function is being called every time the browser is refreshed adding more listeners.

Have you found a workaround for the issue?

@captainjapeng
Copy link

I may have found as solution, you can check if the event is already listened using hasListeners()

  if (!chrome.tabs.onUpdated.hasListeners()) {
    chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
      // ...
    })
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite kind/bug 🐞 mode/bex Qv2 🔝 Quasar v2 issues
Projects
None yet
Development

No branches or pull requests

3 participants