Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

WhatsApp Web stopped working around 2018-11-30 - Asks for Google Chrome ≥ 36 #719

Closed

Description

@prashant-shahi

Description

WhatsApp Web was working so well until few days back. Now when the application is started, it says the following:

WhatsApp works with Google Chrome 36+
To use WhatsApp, update Chrome or use Mozilla Firefox, Safari, Microsoft Edge or Opera.

Update Google Chrome

Natifier WhatsApp Web

Steps to reproduce issue

$ nativefier --name "WhatsApp Web" https://web.whatsapp.com
$ ./whatsapp-web-linux-x64/whatsapp-web

Details

  • Are you nativefying a public website? Yes.
  • Feature request? No.
  • Full nativefier command used to build your app: nativefier --name "WhatsApp Web" https://web.whatsapp.com
  • Version of Nativefier (run nativefier --version): v7.6.8
  • Version of node.js (run node --version): v8.10.0
  • OS: Ubuntu 18.04.1 LTS - Bionic
  • Error message / stack trace (if any): None.

Activity

  1. ronjouch commented on Nov 30, 2018

    @ronjouch
    Contributor

    @coolboi567 just update Nativefier and re-package the app. Yes we know we should do a better job at communicating this to users, see #556; contributions welcome.

  2. bitlab-code commented on Nov 30, 2018

    @bitlab-code

    same issue with vers. 7.6.8
    I think this issue need to be open

  3. ronjouch commented on Nov 30, 2018

    @ronjouch
    Contributor

    @bitlab-code Nativefier 7.6.8 ships with a default Electron version of 3.0.3, based on Chrome 66. Are you sure you did re-package your app with it, by re-running the nativefier command used to package it? If yes, then inside your nativefied app can you pop open the inspector (Ctrl/Cmd+Shift+I) and in the console type navigator.userAgent . What does it output?

  4. bitlab-code commented on Nov 30, 2018

    @bitlab-code

    @ronjouch command + log
    2018-11-30 02 56 24 pm

  5. ronjouch commented on Nov 30, 2018

    @ronjouch
    Contributor

    @bitlab-code thanks, your setup looks good indeed.

    WhatsApp must be doing some kind of new userAgent sniffing / feature detection that results in blocking Nativefier. Patches welcome.

  6. changed the title [-]WhatsApp Web stopped working - Asks for G-chrome update[/-] [+]WhatsApp Web stopped working around 2018-11-10 - Asks for Google Chrome ≥ 36[/+] on Nov 30, 2018
  7. changed the title [-]WhatsApp Web stopped working around 2018-11-10 - Asks for Google Chrome ≥ 36[/-] [+]WhatsApp Web stopped working around 2018-11-30 - Asks for Google Chrome ≥ 36[/+] on Dec 2, 2018
  8. lima-eduardo commented on Dec 2, 2018

    @lima-eduardo

    As a "workaround" you can go to 'edit > clear app data' and rescan the QR code.

  9. saulocastelo commented on Dec 3, 2018

    @saulocastelo

    As a "workaround" you can go to 'edit > clear app data' and rescan the QR code.

    Better "workaround"

    Steps:

    • Open DevTools (Ctrl+Shift+i)
    • Application
    • Service Workers
    • Bypass for network
    • Reload (Ctrl+r)
    • Close DevTools

    Or inject this code

    if (document.body.innerText.replace(/\n/g, ' ').search(/whatsapp works with.*to use whatsapp.*update/i) === 0)
    	navigator.serviceWorker.getRegistration().then(function (r) { r.unregister(); document.location.reload() });
  10. lipe1966 commented on Dec 11, 2018

    @lipe1966

    sorry for the noob question.
    Where should i Inject the above code?

  11. vip9 commented on Dec 11, 2018

    @vip9

    "Bypass for network" works for me only once.

  12. 65 remaining items

  13. renyhp commented on Oct 21, 2020

    @renyhp

    Is there a way to inject the code without building the app again?

    EDIT: Yes, there is. Simply insert @aarestu's code in resources/app/inject/inject.js.

  14. cr3ative commented on Jun 14, 2021

    @cr3ative

    I just had to "get around" this and it's working fine with the "safari" user agent setting. Here's my build command:

    nativefier https://web.whatsapp.com --inject whatsapp.css --title-bar-style "hiddenInset" --name "WhatsApp" --darwin-dark-mode-support --background-color "#36393f" --counter "true" --bounce --user-agent "safari"

    whatsapp.css:

    /* site.css */
    
    /* header is draggable... */
    header {
      -webkit-app-region: drag;
    }
    
    /* but any buttons inside the header shouldn't be draggable */
    header button {
      -webkit-app-region: no-drag;
    }
    
    /* perhaps move some items out of way for the traffic light */
    #side header > div:first-of-type {
      margin-left: 75px;
    }
  15. nielstron commented on Aug 8, 2021

    @nielstron

    The injection code to make whatsapp work in a nativefier app recently stopped working for me as well.

    However, in case anyone else has the same issue, here is my workaround/new injection js (somewhat more reliable then the previous one?):

    // unregister serviceworker after startup -> don't interfere at next startup
    let deleteFun = function(){
      if("serviceWorker" in navigator){
        navigator.serviceWorker.getRegistrations().then(function(e){
         //console.log(e);
         for(r of e){
           r.unregister();
         }
       });
      }};
    deleteFun();
    setInterval(deleteFun,1000);

    (already in https://github.com/nielstron/ubuntu.whatsapp-nativefier)

    It might be a good idea to include it in future releases of the package if more people have this issue.

    EDIT: just noticed that this is very close to @aarestu s code. Leaving this for increased diversity...
    UPDATE: deregistering every time (even if there is no message informing you about the chrome version) makes restarting after newly opening the app unnecessary. Hence a merged/improved version of @aarestu s code below

    function recheck () {
        navigator.serviceWorker.getRegistrations().then((registrations) => {
            for(registration of registrations){
                 registration.unregister();
            }
            if (document.querySelector("body[class='page-version']")) {
                console.log("reload");
                document.location.reload();
             }
        });
        setTimeout(recheck, 5000); // callback
    }
    recheck();
  16. Nowaker commented on Sep 29, 2021

    @Nowaker

    The problem with Whatsapp is caused by Nativefier, not the injection code we use to make it work. Nativefier fails to correctly load the inject code.

    image

    Uncaught ReferenceError: log is not defined from https://github.com/nativefier/nativefier/blob/master/app/src/preload.ts#L78

    function injectScripts() {
        const needToInject = fs.existsSync(exports.INJECT_DIR);
        if (!needToInject) {
            return;
        }
        // Dynamically require scripts
        try {
            const jsFiles = fs
                .readdirSync(exports.INJECT_DIR, { withFileTypes: true })
                .filter((injectFile) => injectFile.isFile() && injectFile.name.endsWith('.js'))
                .map((jsFileStat) => path.join('..', 'inject', jsFileStat.name));
            for (const jsFile of jsFiles) {
                log.debug('Injecting JS file', jsFile);  // <------------- PROBLEM HERE
                require(jsFile);
            }
        }
        catch (err) {
            log.error('Error encoutered injecting JS files', err);
       }

    log is not defined, so the code never goes to require(jsFile). Instead all you get is:

    VM1776 preload.js:84 Uncaught ReferenceError: log is not defined
        at injectScripts (VM1776 preload.js:84)
        at HTMLDocument.<anonymous> (VM1776 preload.js:29)
    

    I don't know why log is undefined - especially given const log = console; in the Typescript source - but the nativefied WhatsApp from https://aur.archlinux.org/packages/whatsapp-nativefier is broken for this reason.

    For full context, here's the preload.js as seen by me:

    (function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { "use strict";
    var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
        if (k2 === undefined) k2 = k;
        Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
    }) : (function(o, m, k, k2) {
        if (k2 === undefined) k2 = k;
        o[k2] = m[k];
    }));
    var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v });
    }) : function(o, v) {
        o["default"] = v;
    });
    var __importStar = (this && this.__importStar) || function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
        __setModuleDefault(result, mod);
        return result;
    };
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.INJECT_DIR = void 0;
    /**
     * Preload file that will be executed in the renderer process.
     * Note: This needs to be attached **prior to imports**, as imports
     * would delay the attachment till after the event has been raised.
     */
    document.addEventListener('DOMContentLoaded', () => {
        injectScripts(); // eslint-disable-line @typescript-eslint/no-use-before-define
    });
    const fs = __importStar(require("fs"));
    const path = __importStar(require("path"));
    const electron_1 = require("electron");
    // Do *NOT* add 3rd-party imports here in preload (except for webpack `externals` like electron).
    // They will work during development, but break in the prod build :-/ .
    // Electron doc isn't explicit about that, so maybe *we*'re doing something wrong.
    // At any rate, that's what we have now. If you want an import here, go ahead, but
    // verify that apps built with a non-devbuild nativefier (installed from tarball) work.
    // Recipe to monkey around this, assuming you git-cloned nativefier in /opt/nativefier/ :
    // cd /opt/nativefier/ && rm -f nativefier-43.1.0.tgz && npm run build && npm pack && mkdir -p ~/n4310/ && cd ~/n4310/ \
    //    && rm -rf ./* && npm i /opt/nativefier/nativefier-43.1.0.tgz && ./node_modules/.bin/nativefier 'google.com'
    // See https://github.com/nativefier/nativefier/issues/1175
    // and https://www.electronjs.org/docs/api/browser-window#new-browserwindowoptions / preload
    exports.INJECT_DIR = path.join(__dirname, '..', 'inject');
    /**
     * Patches window.Notification to:
     * - set a callback on a new Notification
     * - set a callback for clicks on notifications
     * @param createCallback
     * @param clickCallback
     */
    function setNotificationCallback(createCallback, clickCallback) {
        const OldNotify = window.Notification;
        const newNotify = function (title, opt) {
            createCallback(title, opt);
            const instance = new OldNotify(title, opt);
            instance.addEventListener('click', clickCallback);
            return instance;
        };
        newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
        Object.defineProperty(newNotify, 'permission', {
            get: () => OldNotify.permission,
        });
        // @ts-expect-error TypeScript says its not compatible, but it works?
        window.Notification = newNotify;
    }
    function injectScripts() {
        const needToInject = fs.existsSync(exports.INJECT_DIR);
        if (!needToInject) {
            return;
        }
        // Dynamically require scripts
        try {
            const jsFiles = fs
                .readdirSync(exports.INJECT_DIR, { withFileTypes: true })
                .filter((injectFile) => injectFile.isFile() && injectFile.name.endsWith('.js'))
                .map((jsFileStat) => path.join('..', 'inject', jsFileStat.name));
            for (const jsFile of jsFiles) {
                log.debug('Injecting JS file', jsFile);
                require(jsFile);
            }
        }
        catch (err) {
            log.error('Error encoutered injecting JS files', err);
        }
    }
    function notifyNotificationCreate(title, opt) {
        electron_1.ipcRenderer.send('notification', title, opt);
    }
    function notifyNotificationClick() {
        electron_1.ipcRenderer.send('notification-click');
    }
    // @ts-expect-error TypeScript thinks these are incompatible but they aren't
    setNotificationCallback(notifyNotificationCreate, notifyNotificationClick);
    electron_1.ipcRenderer.on('params', (event, message) => {
        log.debug('ipcRenderer.params', { event, message });
        const appArgs = JSON.parse(message);
        log.info('nativefier.json', appArgs);
    });
    electron_1.ipcRenderer.on('debug', (event, message) => {
        log.debug('ipcRenderer.debug', { event, message });
    });
    //# sourceMappingURL=preload.js.map
    }.call(this, exports, require, module, __filename, __dirname); });
  17. TheCleric commented on Sep 29, 2021

    @TheCleric
    Collaborator

    The problem with Whatsapp is caused by Nativefier, not the injection code we use to make it work. Nativefier fails to correctly load the inject code.
    I don't know why log is undefined - especially given const log = console; in the Typescript source - but the nativefied WhatsApp from https://aur.archlinux.org/packages/whatsapp-nativefier is broken for this reason.

    @Nowaker, I agree with your assessment. Not sure what is causing that log definition to be missing as we added that 4 months ago (and looking through the Arch deps, they should be on a version that includes it). We could add a workaround, but my fear would be that somehow that code wouldn't make it upstream just as the const log = console; does not.

  18. Nowaker commented on Sep 29, 2021

    @Nowaker

    Let's find out why log is undefined. PKGBUILD for nodejs-nativefier doesn't do anything crazy. It purely uses your project, without modifications:

    source=(http://registry.npmjs.org/$_npmname/-/$_npmname-$_npmver.tgz)
    npm install -g --cache "${srcdir}/npm-cache" --prefix "$pkgdir/usr" "$srcdir/$_npmname-$pkgver.tgz"
    

    I've just built the latest version, 45.0.4, just to make sure.

    -_npmver=45.0.1
    +_npmver=45.0.4
    -sha256sums=('7e2faca780c66fa6188bd7e55093822cffcee950c008240c21799ab5edf312e6')
    +sha256sums=('SKIP')

    But still no change. log is still undefined:
    image

    % cat /opt/whatsapp-nativefier/resources/app/lib/preload.js|grep log
                log.debug('Injecting JS file', jsFile);
            log.error('Error encoutered injecting JS files', err);
        log.debug('ipcRenderer.params', { event, message });
        log.info('nativefier.json', appArgs);
        log.debug('ipcRenderer.debug', { event, message });
    
  19. Nowaker commented on Sep 29, 2021

    @Nowaker

    Okay... I've spotted something silly in Whatsapp's PKGBUILD.

      sed -i -e "/loglevel/d" "${srcdir}/${_folder}/resources/app/lib/preload.js"

    This removes the line that is very required... Checking it now.

  20. Nowaker commented on Sep 29, 2021

    @Nowaker

    Yeah, that fixes the problem. Not sure why it was there. Submitting a patch to the PKGBUILD.

  21. added a commit that references this issue on Sep 30, 2021
  22. lighterowl commented on Oct 23, 2021

    @lighterowl

    Not sure why it was there.

    I introduced this back in March 2020 with the following comment in the AUR :

    I have no idea about JavaScript or if this doesn't break something half-important, but the app seems to work for me now.

    The nativefier app wouldn't load at all back then (due to this), and this magic line is what made it all work. I'm glad that this isn't needed anymore and that this was looked at by somebody who actually knows what they're doing.

  23. kem-a commented on Nov 12, 2021

    @kem-a

    For me only code snippet from nielstron comment worked using safari user agent. Anything else just fails, including code snippet on main README.md page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions