nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.31k stars 3.88k forks source link

argv is always empty after using an app for a while with a custom scheme #7645

Open obshksw opened 3 years ago

obshksw commented 3 years ago

NWJS Version : 0.50.2 (Both SDK and Normal) Operating System : MacOS Catalina and Big Sur

Expected behavior

With a custom URL scheme, the app is invoked correctly but after a while, the args are not passed to nwjs anymore. (argv is always empty) If I change the CFBundleURLName to something else, it starts working again without changing anything else. Going back to an older CFBundleURLName or removing the app completely and reinstalling it does nothing, it is like the CFBundleURLName is broken forever.

Actual behavior

args are always passed.

How to reproduce

In my example, I load a web page that contains en embedded flash. Everything works well. (when it works) -When the app is already opened, it always works. (Using the onOpen event) -I tried going back on an older version and the args are always passed. (The bug isn't there) (0.46.4) -It seems that trying to open a device in PepperFlash breaks it automatically. -Also tried to do it without using the Iframe (directly using window.location.href), and the problem still occurs. -Invoking directly myapp.app/Contents/MacOS/nwjs in command line always works, even when it is broken using the scheme. (argv is filled in correctly)

package.json

"name": "MyApp",
  "version": "0.1",
  "main": "index.html",
  "window": {
    "resizable": true
  },

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>MyApp</title>
  </head>
<body>
    <script src="main.js"></script>
<div id="content">
 <iframe id="flashFrame" width="100%" height="100%" frameborder="0" src=""></iframe>
</div>
  </body>
</html>

main.js

var win = nw.Window.get();

win.window.onload = function() {
 console.log("onLoad: ", nw.App.argv);
 if(nw.App.argv.length > 0) {
       win.window.document.getElementById("flashFrame").src = nw.App.argv[0];
 }
}

nw.App.onOpen.addListener((url) => {
   console.log("onOpen:", url);
});

Added this to the Info.plist:

<dict>
 <key>CFBundleURLName</key>
 <string>com.whatever.myapp1</string>
 <key>CFBundleURLSchemes</key>
 <array>
 <string>myapp</string>
 </array>
 </dict>

Let me know if you need more infos... We've been losing our mind on this the whole week!

corwin-of-amber commented 3 years ago

Can you please describe "for a while"? How long does one have to be using the app with given CFBundleURLName before it breaks?

Also, is loading a flash object essential in order to reproduce the bug? You said you tried without an <iframe>, does it mean without the flash plugin as well?

obshksw commented 3 years ago

Yeah I know "for a while" seems kinda vague, but I don't really have something specific. Sometimes it failed after one time, sometimes it failed after I stopped trying for 5/10/15min... It did not seem to have a specific reason other than opening a device inside the flash, which made it stop working 100% of the time. Other than that it looked it was at a random time? Like something getting garbage collected? I know it does not makes sense, but that's the feeling of it, like it was never after the same time.

And what's even weirder, if I put an previously failed CFBundleURLName, let's say even if I reboot, it is forever broken! But the invocation of the app still works, so the scheme is still registered correctly. It is mind boggling.

As for without Flash, I don't think I tried without loading the Pepper Flash plugin. Trying without the <iframe> was still loading a page with the Flash in it. We were kinda in a hurry to make it work before christmas, so I haven't had time to try without the Flash, sorry!

corwin-of-amber commented 3 years ago

Wow, there is almost no documentation about what CFBundleURLName is and what is being done with it. I am guessing it is stored in some internal map used by macOS somewhere. I assume you were testing it with open myapp://some-path? Did you try opening myapp:// URLs in different browsers? Also, when a certain CFBundleURLName is broken, is it broken for all users or just the current user?

Perhaps some of the devs here have some more experience with Apple (@rogerwang ?).

kakysha commented 2 years ago

Same bug in here. macOS Monterey, nwjs 0.55-sdk, M1 chip btw, so the app is launched through Rosetta. argv always empty when my app is opened through custom URL schemes as for the author of this issue. When app is already opened, the 'open' event handles correctly. Tried different combinations, open /Applications/Myapp.app myapp://123, by entering just the url into Safari and Chrome address bar or by clicking the links in different apps and webpages. When the app is not running, argv always empty.