markusfisch / BinaryEye

Yet another barcode scanner for Android
https://play.google.com/store/apps/details?id=de.markusfisch.android.binaryeye
MIT License
1.42k stars 117 forks source link

Need to scan QR code twice when opening intent from PWA/Installed web app #478

Closed Kagee closed 1 month ago

Kagee commented 1 month ago

I'm trying to use Binary Eye from a PWA (installed web app, what internally apparently called "webapk" in Android). I intend to have the scan returned as a call to the PWA, so the url is as follows: binaryeye://scan?ret=https%3A%2F%2Fscan.h2x.no%2Fscan%3Fresult%3D{RESULT}

When i open the intent from Chrome, Binary Eye scans the code, and opens the return URL, thus triggering Android to open the PWA. The value is successfully captured by the PWA (since it is just a web page that now has a query value). This is the expected flow, and also what i would expect when starting the flow from the PWA.

However, when i open the intent from inside the PWA, I have to scan the code twice before the PWA opens with the result. Based on that i do not see any web requests for the PWA before after the second scan, i belive this is Binary Eye not opening the return url, and not the PWA restarting the scan/intent.

The web page is not avaliable without login, but i can set up an public example if required. I do not belive the login is at fault, since the PWA opens just fine if the scan chain was started in Chrome.

This https://photos.app.goo.gl/1o51uWEtHGgM3WXM9 video shows the following

  1. Open intent from Chrome browser. Instant scan, and instant PWA open.
  2. Open intent from Chrome browser. Scroll through settings. Instant scan, and instant PWA open.
  3. Open intent from PWA (same website, just as a installed web app). Successfull scan w. vibration. Second successfull scan w. vibration (may be hard to catch). PWA opens.
  4. Open intent from PWA. Successfull scan w. vibration. Quicly pan away to show that PWA does not open after scan. Show settings. Second successfull scan w. vibration. PWA opens.

Google Pixel, Android 14

markusfisch commented 1 month ago

Hm, well, looking at the video, I can tell there is something happening at the first (successful but not returning) scan (in case 4) because the screen gets black for a short moment. This means the camera was closed and re-opened. So I guess the Intent to open the return URL (here) was indeed started but somehow failed 🤔

Obviousely, the return URL is registered with the PWA because otherwise it wouldn't open on the second scan. So I'm really a bit puzzled…

Kagee commented 1 month ago

For testing: https://pwa-test.h2x.no/ - i can replicate the problem with this bare-bones setup. The app is just a web page with two Binary Eye links that prints the GET, POST and HTTP header data.

If the PWA install box does not pop up, in Chrome, do "Add to home screen". Instead of "Addo to home screen" it should suggest "Install app".

Kagee commented 1 month ago

I can, annoyingly enough, not replicate this on a Pixel 7 emulator. I had to upgrade Chrome on the emulator image for the PWA to install properly, if not it was just added as a homescreen shortcut. Uou can see the difference because homescreen shortscuts hav a chrome icon in the corner.

Kagee commented 1 month ago

And, following that revelation, reisntalling Binary Eye on the actual device appears to have fixed the issue. I would assume some setting or other that i at some time changed in Binary Eye was at fault? 🤔 However, when comparing the settings from the video with the current, apparently working settings on the same phone, i see no difference.

Kagee commented 1 month ago

Also possible Chrome updated between now and then, can't really verify since i didn't note version numbers of Chrome. Also can't find any related bugs or changes in recent Chrome for Android.

markusfisch commented 1 month ago

That's interesting! Frankly, I still have no idea what could have been the reason, and that the bug just vanished with a fresh installation of Binary Eye is surprising. But good to know! Thanks a lot for reporting! 👍

I would assume some setting or other that i at some time changed in Binary Eye was at fault?

I really doubt that, too. There's no preference that would have any effect on starting this Intent.

Also possible Chrome updated between now and then, can't really verify since i didn't note version numbers of Chrome. Also can't find any related bugs or changes in recent Chrome for Android.

Maybe 🤷‍♂️