Xubuntu 14.04 および Firefox 45.0.1 での作業はこちら
バックグラウンドスクリプト内からブラウザウィンドウを自動的にフルスクリーン状態にしようとしていますlocation.hash == "#fullscreen"
.
これは、コンテンツ スクリプトがリッスンする を実行することにより、特権 Web ページのスクリプトから要求されますpostMessage()
。コンテンツ スクリプトは、この要求をバックグラウンド スクリプトに委任します。
console.log()
期待される値を含め、すべてが期待どおりに機能しますbackground.js
(以下の関連するソース コード スニペットを参照してください)。ただし、ウィンドウはフルスクリーンにはなりません。実際には何も起こらず、ユーザーが開始したイベントを要求することに関するコンソールの警告もありません。これは、Web ページ自体から同様のことを試みた場合に受け取るはずです (これが、最初にこの拡張機能を作成することになった理由です) 。たとえば、試しw.state = 'minimized'
ても何もしません。
質問:
Firefox WebExtensions API は
window.state
(既に) 変更をサポートするはずですか?もしそうなら、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 );