ubuntu - 后台脚本中的 window.state = 'fullscreen' 应该可以工作吗?

标签 ubuntu firefox-addon fullscreen firefox-addon-webextensions

此处使用 Xubuntu 14.04 和 Firefox 45.0.1

如果 location.hash == "#fullscreen",我正在尝试从后台脚本中自动将浏览器窗口置于全屏状态。

这是通过执行内容脚本监听的 postMessage() 从特权网页脚本请求的,内容脚本又将此请求委托(delegate)给后台脚本。

一切都按预期工作,包括 background.js 中预期的 console.log() 值(请参阅下面的相关源代码片段)...除了窗口不会全屏显示;实际上没有发生任何事情,也没有关于需要用户启动事件的控制台警告,如果我尝试从网页本身尝试类似的操作,我会收到该警告(这就是为什么我转向创建此扩展,在第一个地方)。例如,尝试 w.state = 'minimized' 也不会执行任何操作。

问题:

  1. Firefox WebExtensions API 是否应该支持 window.state 更改(已经)?

  2. 如果是这样,Firefox WebExtensions API 是否应该拥有足够的特权来在没有显式用户交互的情况下启动全屏?

  3. 如果是这样,我是否应该被允许在我尝试执行此操作的上下文中执行此操作?

  4. (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"
]

特权网页脚本:

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 );

最佳答案

啊...我刚刚发现了 windows.update()方法,当我尝试通过 updateInfo 参数对象设置 state 时,它确实给出了一个通知:

Type error for parameter updateInfo (Property "state" is unsupported by Firefox) for windows.update

真是可惜了。

关于ubuntu - 后台脚本中的 window.state = 'fullscreen' 应该可以工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36703730/

相关文章:

javascript - 在 Firefox 附加组件中对 XML 使用 XPath

javascript - 如何检查 Javascript 是否从 Firefox 扩展中激活?

firefox - 使用新标签页替换插件打开新标签时,如何保持地址栏清晰?

Android - 打开和关闭屏幕时,覆盖在全屏视频最后一帧上的 View 无法正确重绘

python - 在 Ubuntu 12.10 上安装 scrapy

ubuntu上的mongoDB服务没有修复

c++ - Ubuntu 上 Netbeans 7.3+ 中 c++ 的解析器索引/缓存的位置

jqgrid全屏切换,窗口宽高

actionscript-3 - FULL_SCREEN_INTERACTIVE 模式 : the "Allow" button click is passed to the application

php - 我如何告诉 Phing PHPUnit 的安装位置?