0
私はgreasemonkeyスクリプトからイベントエミッタを聞く方法を理解しようとしていますが、アクセス違反エラー(Permission denied to access object
)が続きます。greasemonkeyスクリプトからイベントを聴く
var emitter = function(){
this.events = {};
}
emitter.prototype.on = function(eventName, closure){
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(closure);
};
emitter.prototype.emit = function(eventName, data){
if(this.events[eventName]){
this.events[eventName].forEach(function(fn){
return fn(data);
});
}
}
var test = new emitter();
test.emit('test', {data:'test'});
スクリプトこれは、アクセス違反エラーが(これはしばらく前に働いていたが、私はそれはパッチを適用してしまったと思いスロー
:
ページ
ページは、単純なイベント・エミッターが含まれていますまたは何か):
unsafeWindow.test.on('test', function(data){
console.log(data);
});
userscriptメタブロックに '// @ grant unsafeWindow'がありますか? – wOxxOm
@wOxxOmはい。 unsafeWindowはうまく動作します。 – Rai
安全でないコンテキストに関数をエクスポートしてみましょう: 'unsafeWindow.test.on( 'test'、exportFunction(function(data){....}))' – wOxxOm