0

So basicly I'm injecting a script into a frame to get a specific variable but I get the following error: content.exenv2.exerciseframe.singletons is undefined

But when I access this variable thru to firebug console it works. Also I can access other variable from the frame just not the one I need

Full Error

error: dwh: An exception occurred.
TypeError: content.exenv2.exerciseframe.singletons is undefined
resource://jid1-os5kkx1kvkogmq-at-jetpack/dwh/data/inject.js 2
Traceback (most recent call last):
  File "resource://jid1-os5kkx1kvkogmq-at-jetpack/dwh/data/inject.js", line 2, i
n
    var length = content.exenv2.exerciseframe.singletons.entries["TkExerciseItem
s_()"].length;

First 2 lines of code

var test = content.exenv2.exerciseframe.loadingTimer; //This works
var length = content.exenv2.exerciseframe.singletons.entries["TkExerciseItems_()"].length; //Error 
4

1 回答 1

0

显然,Firefox 插件无法访问原型变量,这就是singletons的情况。

https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/guides/content-scripts/accessing-the-dom.html

如上面的链接所述,应使用 unsafeWindow 访问此类变量。

所以工作代码是:

var length = unsafeWindow.content.exenv2.exerciseframe.singletons.entries["TkExerciseItems_()"].length;
于 2013-10-21T20:15:01.403 回答