0

Having a subtle javascript problem in the web browser on an older iPhone and also on an older Samsung S4. It runs nicely on a 2-year old Acer phone. Trying to pinpoint the problem I split the JS in several script blocks and put alert calls in each:

<script>
    // ...JS code...
    alert('JS0 end');
</script>
<script>
try{
    alert('JS1 start');
    // button handler to scan a barcode
    function scan_barcode() {
        $('#div_viewarea').show();
        $('#input_barcode').val('');// clear the barcode field
        log('scanning...');//clear message field
        // install the handler to process a barcode fount by quagga
        Quagga.onDetected(quagga_found_barcode);//callback stops Quagga
        // The Quagga config data for the LiveStream method accessing the camera directly
        var quagga_config_livestream = {
            inputStream: {
                //constraints: { width: 500, height: 500 },
                //area: { top: '50%', right: '50%', left: '50%', bottom: '50%' },
                target: document.querySelector('#div_viewarea'),
                name: "Live",
                type: "LiveStream"
            },
            quagga_decoders
        };
        // initialize/start/run the Quagga barcode module
        Quagga.init(quagga_config_livestream, quagga_on_init);
        return;
    }
    alert('JS1 end');
} 
catch(e){ 
    alert('exception 1: ' + e);
}
</script>
<script>
    // ...JS code...
    alert('JS2 end');
</script>

On the Acer phone I get dialogs for JS0/1/2, but on the iPhone only for JS0+2, so something goes wrong in the middle script block where I show the full JS code.

Running the page on firefox on Windows, the F12 debugger shows no problems. But on the mobile phone browsers there is no F12 debugger.

I also tried to get the JS exception with try/catch, but no dialog is shown for the exception.

So my questions are: - what is the problem in the middle script block? - how to debug JS code on a phone? - are there better methods than just splitting in several script blocks?

Incidentally, the code in the second block is not very interesting on the older phones, because according to the docs on Quagga , the older phones do not support the MediaDevices API. But if I put all the JS code in one script block, the JS past the problem in the middle won't run at all.


Update:

I regard this as a bug in older browser/devices. It works OK in Firefox on the Samsung S4 though. I was able to isolate the problem to the assignment of variable quagga_config_livestream but find it extremely surprising that neither an exception is fired, nor the earlier alert showed its dialog. Because this bug occurs in a piece of JS code that is not relevant for older devices that do not support the MediaDevices API, I just sandboxed that few lines of JS in its own script block and won't bother to install new tools to remotely debug this code on the device itself.

Roland
  • 4,619
  • 7
  • 49
  • 81
  • Is this an App or is this occuring in the iPhone's web browser? – dimwittedanimal Mar 12 '18 at 16:39
  • What version of iOS is this? – dimwittedanimal Mar 12 '18 at 16:40
  • @dimwittedanimal This should run on all browsers on all phones. The browser on this phone does not have a menu for help/about with the version. In Settings, I see the license from 2014, and a "version" for the phone of 7.1.2 if that tells you anything. This problem is in the phone's web browser. Also on older Samsung S4 – Roland Mar 12 '18 at 16:46
  • Open Settings > Safari > Advanced... is there a setting for Web Inspector? That's about the only way I can think you'd be able to debug it. – dimwittedanimal Mar 12 '18 at 16:52
  • 1
    @dimwittedanimal I am finding info like https://stackoverflow.com/a/9198121/1845672 about tools to debug web pages on mobile. I will try those for Android first, because I would rather not have to invest in a Mac for this. Still mind boggling that my simple looking JS code is behaving strange – Roland Mar 12 '18 at 16:58
  • 1
    I don't blame you. Good luck. – dimwittedanimal Mar 12 '18 at 16:59

0 Answers0