注入されたスクリプトは、私が試したクロスドメインのxmlhttpリクエストを実行できないため、マニュアルでは、注入されたスクリプトからバックグラウンドスクリプトにメッセージを送信してジョブを実行するように勧められています。しかし、メッセージを機能させることができません。
これは私のコードです。ファイルは 3 つだけで、可能な限り単純な拡張子です。
config.xml
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" id="http://www.example.org/helloworld">
<name>postMessage-testcase</name>
<description>check if opera's postMessage fails</description>
</widget>
index.html
<!doctype html>
<html lang="en">
<head>
<script>
opera.extension.onmessage = function(event) {
alert("get the message!");
opera.extension.postMessage("posting reply");
};
</script>
</head>
<body></body>
</html>
includes/user.js
// ==UserScript==
// @include *apod.nasa.gov*
// ==/UserScript==
opera.extension.onmessage = function(event) {
alert("got reply !");
};
alert("yep, I'm on apod, proceeding with messages");
opera.extension.postMessage("message body");
ユーザーが apod.nasa.gov を開くと、スクリプトはメッセージを前後に送信する必要がありますが、ここで送信されるメッセージは 1 つだけで、メッセージは発生せず、コンソールにもエラーは表示されません。