You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/10/14 14:22:14 UTC

[cordova-js] branch master updated: Do not try to replace window.navigator (#215)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-js.git


The following commit(s) were added to refs/heads/master by this push:
     new c8aca1e  Do not try to replace window.navigator (#215)
c8aca1e is described below

commit c8aca1efbdb60a173179407fd5e96a7add81850d
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Mon Oct 14 16:22:07 2019 +0200

    Do not try to replace window.navigator (#215)
    
    window.navigator is a read-only property. Thus the current code for
    replacing it cannot succeed in a [spec][1] compliant browser. In strict
    mode the attempt will throw an error. In sloppy mode, the one Cordova is
    currently running in, the attempt is silently ignored.
    
    Since apps seem to have been doing OK with the original navigator object
    we should just remove the code trying to replace it.
    
    [1]: https://html.spec.whatwg.org/multipage/window-object.html#the-window-object
---
 src/common/init.js | 29 -----------------------------
 1 file changed, 29 deletions(-)

diff --git a/src/common/init.js b/src/common/init.js
index 031ca9b..31a4900 100644
--- a/src/common/init.js
+++ b/src/common/init.js
@@ -24,7 +24,6 @@ var cordova = require('cordova');
 var modulemapper = require('cordova/modulemapper');
 var platform = require('cordova/platform');
 var pluginloader = require('cordova/pluginloader');
-var utils = require('cordova/utils');
 
 var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
 
@@ -44,34 +43,6 @@ window.setTimeout(function () {
     }
 }, 5000);
 
-// Replace navigator before any modules are required(), to ensure it happens as soon as possible.
-// We replace it so that properties that can't be clobbered can instead be overridden.
-function replaceNavigator (origNavigator) {
-    var CordovaNavigator = function () {};
-    CordovaNavigator.prototype = origNavigator;
-    var newNavigator = new CordovaNavigator();
-    // This work-around really only applies to new APIs that are newer than Function.bind.
-    // Without it, APIs such as getGamepads() break.
-    if (CordovaNavigator.bind) {
-        for (var key in origNavigator) {
-            if (typeof origNavigator[key] === 'function') {
-                newNavigator[key] = origNavigator[key].bind(origNavigator);
-            } else {
-                (function (k) {
-                    utils.defineGetterSetter(newNavigator, key, function () {
-                        return origNavigator[k];
-                    });
-                })(key);
-            }
-        }
-    }
-    return newNavigator;
-}
-
-if (window.navigator) {
-    window.navigator = replaceNavigator(window.navigator);
-}
-
 if (!window.console) {
     window.console = {
         log: function () {}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org