Chrome扩展程序是否可以更改Chrome设置(在新窗口/弹出窗口中打开)? [英] Can a Chrome extension change Chrome settings (open in new window / popup)?

查看:633
本文介绍了Chrome扩展程序是否可以更改Chrome设置(在新窗口/弹出窗口中打开)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似的问题被问到这里,但没有令人满意的答案。< b
我试图用扩展名更改2个Chrome设置。


  1. 导致浏览器打开新链接为
  2. 导致浏览器接受来自特定网址的弹出窗口

我已经查看了文档,但找不到答案。

任何人都可以帮助我解决这个问题吗? 解决方案

没有设置将链接作为选项卡而不是窗口打开。您可以通过 chrome.contentSettings 更改弹出窗口首选项> API。

所有请求的功能也可以间接启用。一些想法:


  1. 新窗口,而不是选项卡。


    1. 检测创建通过 chrome.tabs.onCreated
    2. 检测窗口是否在另一个窗口内打开:

      使用 tab.id 属性从上一个事件侦听器获取窗口对象,使用 chrome.extension.getViews 。然后,检查 window.opener 属性以确定链接是否从另一个选项卡打开。


      这个链接可能不起作用 rel =noreferrer 属性集。


      使用 chrome.windows.create ,将 tabId 。该选项卡将从其上一个窗口中分离出来,并附加到新窗口中。


  2. 您可以重写 window.open 方法,它调用 chrome.tabs.create chrome.windows.create 创建一个新的弹出窗口。

    全局重写可以通过使用 status ==扩展/ tabs.html#event-onCreated =nofollow> chrome.tabs.onUpdated 。完成,然后使用 chrome.extension.getViews 来更改 window.open 方法。确保您创建了缓存版本的窗口 onject,以便在必要时仍可使用原始方法。

这些是必要的信息+文档链接,可帮助您创建所需的功能。祝你好运;)


A similar question was asked here but without a satisfying answer.
I'm trying to do change 2 chrome settings with the extension.

  1. Cause the browser to open new links as tabs and not windows.
  2. Cause the browser to accept pop ups from a specific URL

I have looked in the documentation, but cannot find the answer.
Could anyone help me with this one?

解决方案

There's no setting to open links as tabs instead of windows. You can change the popup preference through the chrome.contentSettings API.

All of the requested features can also be enabled indirectly. Some ideas:

  1. New window instead of tabs.

    1. Detect creation of tabs through chrome.tabs.onCreated.
    2. Detect whether the window was opened from inside another window:
      Use the tab.id property from the previous event listener to get the window object, using chrome.extension.getViews. Then, check the window.opener property to determine whether the link was opened from another tab.
      This might not work when the link has the rel="noreferrer" attribute set.

      Create a new window using chrome.windows.create, passing the tabId. The tab will be detached from its previous window, and attached to the new window.

  2. You can rewrite the window.open method, which invokes chrome.tabs.create and chrome.windows.create to create a new popup window.
    A global rewrite can be done by detecting page loads using chrome.tabs.onUpdated, with status=="complete", then use chrome.extension.getViews to change the window.open method. Make sure that you create a cached version of the window onject, so that the original method is still available when necessary.

These are the necessary information + documentation links which help you to create the desired functionaily. Good luck ;)

这篇关于Chrome扩展程序是否可以更改Chrome设置(在新窗口/弹出窗口中打开)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆