You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Jonathan Bond-Caron (JIRA)" <ji...@apache.org> on 2013/04/08 18:39:17 UTC

[jira] [Updated] (CB-2956) Illegal invocation - CordovaNavigator

     [ https://issues.apache.org/jira/browse/CB-2956?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Bond-Caron updated CB-2956:
------------------------------------

    Description: 
In Cordova 1.4 (possibly a lower version), the following code was added:
 
{code} 
var CordovaNavigator = function() {};
CordovaNavigator.prototype = context.navigator;
context.navigator = new CordovaNavigator();
{code} 

----

That breaks the following existing code :

{code} 
navigator.getUserMedia({video: true}, function(stream){
   MV.camera._stream = stream;
   video.src = window.URL.createObjectURL(stream);
}, 
   function(error){ errorCallback.call(MV.camera, error); }
);
{code} 

Chrome complains with 'Illegal invocation' since getUserMedia() is expected to be executed within the scope of the original window.navigator.

To fix my code, I have to use:

{code} 
navigator.getUserMedia.call(Object.getPrototypeOf(navigator), {video: true}, 
  function(stream){
    MV.camera._stream = stream;
    video.src = window.URL.createObjectURL(stream);
}, 
   function(error){ errorCallback.call(MV.camera, error); }
);
{code} 

I don't think Cordova JS should override any of the default native objects.



  was:
In Cordova 1.4 (possibly a lower version), the following code was added:
 
var CordovaNavigator = function() {};
CordovaNavigator.prototype = context.navigator;
context.navigator = new CordovaNavigator();

----

That breaks the following existing code :

navigator.getUserMedia({video: true}, function(stream){
   MV.camera._stream = stream;
   video.src = window.URL.createObjectURL(stream);
}, 
   function(error){ errorCallback.call(MV.camera, error); }
);

Chrome complains with 'Illegal invocation' since getUserMedia() is expected to be executed within the scope of the original window.navigator.

To fix my code, I have to use:

navigator.getUserMedia.call(Object.getPrototypeOf(navigator), {video: true}, 
  function(stream){
    MV.camera._stream = stream;
    video.src = window.URL.createObjectURL(stream);
}, 
   function(error){ errorCallback.call(MV.camera, error); }
);

I don't think Cordova JS should override any of the default native objects.



    
> Illegal invocation - CordovaNavigator
> -------------------------------------
>
>                 Key: CB-2956
>                 URL: https://issues.apache.org/jira/browse/CB-2956
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: CordovaJS
>    Affects Versions: 2.4.0
>         Environment: Cordova 1.4 running in Chrome Version 26.0.1410.43 m
>            Reporter: Jonathan Bond-Caron
>            Assignee: Filip Maj
>            Priority: Critical
>
> In Cordova 1.4 (possibly a lower version), the following code was added:
>  
> {code} 
> var CordovaNavigator = function() {};
> CordovaNavigator.prototype = context.navigator;
> context.navigator = new CordovaNavigator();
> {code} 
> ----
> That breaks the following existing code :
> {code} 
> navigator.getUserMedia({video: true}, function(stream){
>    MV.camera._stream = stream;
>    video.src = window.URL.createObjectURL(stream);
> }, 
>    function(error){ errorCallback.call(MV.camera, error); }
> );
> {code} 
> Chrome complains with 'Illegal invocation' since getUserMedia() is expected to be executed within the scope of the original window.navigator.
> To fix my code, I have to use:
> {code} 
> navigator.getUserMedia.call(Object.getPrototypeOf(navigator), {video: true}, 
>   function(stream){
>     MV.camera._stream = stream;
>     video.src = window.URL.createObjectURL(stream);
> }, 
>    function(error){ errorCallback.call(MV.camera, error); }
> );
> {code} 
> I don't think Cordova JS should override any of the default native objects.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira