KangoExtensions / kango

Kango framework issue tracker
74 stars 7 forks source link

Error in opera: rangy library not working #35

Closed martinth closed 11 years ago

martinth commented 11 years ago

I'm developing a extension that uses rangy (https://code.google.com/p/rangy/) in a contentscript. When I install this extension in Opera I get the following error when the contentscript starts to run:

US: Undefined variable: rangy
<anonymous function>([arguments not available])@
<anonymous function: evalInSandbox>([arguments not available])@content.js:13
<anonymous function: evalInSandbox>([arguments not available])@content.js:13
<anonymous function: executeScript>([arguments not available])@content.js:272
<anonymous function: run>([arguments not available])@content.js:265
<anonymous function: d.onSuccess>([arguments not available])@content.js:203
<anonymous function: kango.InvokeAsyncModule.prototype.init>([arguments not available])@content.js:169
<anonymous function: kango.InvokeAsyncModule.prototype.init>([arguments not available])@content.js:187
<anonymous function: opera.extension.onmessage>([arguments not available])@content.js:106
@

I suspect that this is somehow related to issue #33 since I had an similiar error with jQuery (that was gone when I used the quick fix posted there).

Steps to reproduce

  1. create a new extension
  2. put rangy-core.js in the src/common folder
  3. create a content script that has // @require rangy-core.js on top of it and any code (i.e. alert("Foo"); in it
  4. build extension and install in opera and reload any page

    What I've tried

When I look at the rangy-cory.js they are using something like

window['rangy'] = (function() {
/* api creating */
return api;
})();

for there core. I have already tried changing this to:

var rangy;
window['rangy'] = rangy = (function() { /* ... */})();

This however doesn't change anything. Additionally I would rathe not like to change the library I'm using. Is there a way to fix this in kango?

akrylysov commented 11 years ago

Opera has several issues with variables visibility scope in content scripts (we have reported to Opera developers about a year ago but no changes).

Change library declaration to:

var rangy;
rangy = window.rangy = function(){/*...*/}

then in content script you can use rangy variable:

kango.console.log(typeof rangy); // object