question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event 'open' on app is triggered once

See original GitHub issue

Win 10 (x64)

  • NWjs 0.62.2 - ok
  • NWjs 0.63.0 - fail

manifest.json:

{
  "name": "test",
  "version": "0.1",

  "app": {
    "background": {
      "scripts": ["init.js"]
    }
  },

  "permissions": [
      "webview",
      "<all_urls>",
      "node",
      "proxy"
  ]
}

init.js:

(function () {
    // open dev tools
    chrome.developerPrivate.openDevTools({ renderViewId: -1, renderProcessId: -1, extensionId: chrome.runtime.id });
    // listener
    nw.App.on('open', (params) => console.log('onOpen', params));
})();

test case:

nw.exe "https://nwjs.io" // open event is triggered
nw.exe "https://nwjs.io" // nothing
nw.exe "https://nwjs.io" // nothing

@rogerwang

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rogerwangcommented, Apr 12, 2022

This is fixed in git and will be available in the next nightly build.

1reaction
sysragecommented, Apr 5, 2022

I created a test to find this regression and it helped narrow-down the behavior. It seems that any event handlers attached to the open event are removed once they fire…

This shows the bug in action. After the first open event, the remaining 5 events do not trigger the event handler:

    const util = require('util');
    const exec = util.promisify(require('child_process').exec);

    let eventFired;
    nw.App.on('open', (params) => {
      console.log('params', params);
      eventFired = true;
    });

    const testOpenEvent = async () => {
      eventFired = false;
      const result = await exec(`${process.argv} ${nw.App.startPath} --testing`);
      if (!eventFired) return false;
      return true;
    };

    (async () => {
      for (let i = 0; i <= 5; i++) {
        console.log(`Test attempt: ${i}`);

        if (! await testOpenEvent()) {
          console.log('FAIL: The `open` event did not fire!');
        }
      }
    })();

image

However, if the event handler is re-attached to the open event every time, it works as expected:

    const util = require('util');
    const exec = util.promisify(require('child_process').exec);

    const testOpenEvent = async () => {
      let eventFired = false
      nw.App.on('open', (params) => {
        console.log('params', params);
        eventFired = true;
      });

      const result = await exec(`${process.argv} ${nw.App.startPath} --testing`);
      if (!eventFired) return false;
      return true;
    };

    (async () => {
      for (let i = 0; i <= 5; i++) {
        console.log(`Test attempt: ${i}`);

        if (! await testOpenEvent()) {
          console.log('FAIL: The `open` event did not fire!');
        }
      }
    })();

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event triggers in Shortcuts on iPhone or iPad - Apple Support
Existing: Triggers your automation when a specific alarm goes off in the Clock app. (After you select this option, select an alarm from...
Read more >
What is the javascript/window event called when app is ...
I have a requirement that I want to trigger a javascript function whenever my app in firefox os phone is launched. Below event...
Read more >
Solved: Onchange event often triggers when screen becomes
Onchange event often triggers when screen becomes visible (date picker control) Greetings PowerAppers, I have a date picker control on an edit form...
Read more >
Is First_open event counting when a user re-install an app?
This event is not triggered when a user downloads the app onto a device, but instead when he or she first uses it....
Read more >
Simple Triggers | Apps Script - Google Developers
To use a simple trigger, simply create a function that uses one of these reserved function ... The event handler triggered when opening...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found