ここでのXubuntu 14.04とFirefox 45.0.1でwindow.state = 'fullscreen'は、動作するはずのバックグラウンドスクリプトからですか?
作業location.hash == "#fullscreen"
場合、私は、自動的にバックグラウンドスクリプト内からフルスクリーン状態にブラウザのウィンドウを置くしようとしています。
これは、コンテンツスクリプトがリッスンするpostMessage()
を実行することによって、特権Webページのスクリプトから要求され、この要求はバックグラウンドスクリプトに委譲されます。
期待されるconsole.log()
の値がbackground.js
(以下の関連するソースコードのスニペットを参照してください)...を含むすべてが正常に動作しますが、ウィンドウはフルスクリーンにはなりません。実際には何も起こりません。ユーザーが開始したイベントを要求するというコンソール警告もありません。を受信しました。これはWebページ自体から似たようなものを試してみました(これが最初です。たとえば、w.state = 'minimized'
を試しても何もしません。
質問:
は
window.state
変更(すでに)をサポートすることになっFirefoxのWebExtensions APIですか?Firefox WebExtensions APIは、明示的なユーザーの操作なしにフルスクリーンを起動するのに十分な特権を持っていますか?
もしそうなら、私は文脈からこれを行うことが許されるべきですか?これをやろうとしていますか?
(X)ubuntuまたは任意のFirefoxの好みがおそらく原因でしょうか?
関連manifest.json
データ:
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://privilegeduri/*"],
"js": ["jquery-1.11.3.min.js", "content.js"],
"run_at": "document_start"
}
],
// I've tried without "fullscreen" as well
"permissions": [
"tabs",
"fullscreen", // no mention of this on MDN, but I tried it anyway
"webNavigation"
]
特権のWebページのスクリプト:
if(location.hash == '#fullscreen') {
if(hasExtension()) { // function that evaluates whether my extension is installed
window.postMessage({
action: 'requestFullscreen'
}, 'http://privilegeduri');
}
}
content.js
スクリプト:
function receiveMessage(e) {
if(e.source === window && e.origin === 'http://privilegeduri') {
switch(e.data.action) {
case 'requestFullscreen':
chrome.runtime.sendMessage(e.data);
break;
}
}
}
window.addEventListener('message', receiveMessage);
background.js
スクリプト:
function receiveMessage(message, sender, sendResponse) {
if(sender.id === chrome.runtime.id && sender.url.match(/^http:\/\/privilegeduri/)) {
switch(message.action) {
case 'requestFullscreen':
browser.windows.get(sender.tab.windowId, {}, function(w) {
console.log(w.state); // outputs 'normal'
w.state = 'fullscreen';
console.log(w.state); // outputs the expected value 'fullscreen'
});
break;
}
}
}
chrome.runtime.onMessage.addListener(receiveMessage);
html5フルスクリーンAPIを試しましたか? - https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API - ? – Noitidart
@Noitidartはい、最終的には、フルスクリーンAPIで動作するようになっています。しかし、再起動しない(ブートストラップされた)アドオン内でのみ。私がこの拡張機能を開発し始めたのは、フルスクリーンAPIがウェブページ内のユーザー開始に限定されていたからです。ただし、残念ながらWebExtensions APIには昇格された特権がありません。 :(そして、私のOPの例でも失敗した後、私の最後の希望は、 "従来の"再起動のないXPCOM APIに設定されました。幸いにも*自律的なフルスクリーンアクティベーションの特権が昇給されています:-) –
@Noitidart PS。 :full-screen API権限を昇格させる 'about:config'プリファレンス' full-screen-api.allow-trusted-requests-only'がありますが、それは私のアドオンのユーザーを*どのような*ウェブサイトでもこの特権を持っていて、私はそれを私のユーザにしたくありません。 :-)私は自分のウェブサイトにこの特権を与えたいだけです。 –