Can a Chrome extension change Chrome settings (open in new window / popup)?

痞子三分冷 提交于 2019-12-02 05:27:45

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!