A similar question was asked here but without a satisfying answer.
I'm trying to do change 2 chrome settings with the extension.
- Cause the browser to open new links as tabs and not windows.
- 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:
- New window instead of tabs.
- Detect creation of tabs through
chrome.tabs.onCreated
. - Detect whether the window was opened from inside another window:
Use thetab.id
property from the previous event listener to get thewindow
object, usingchrome.extension.getViews
. Then, check thewindow.opener
property to determine whether the link was opened from another tab.
This might not work when the link has therel="noreferrer"
attribute set.
Create a new window usingchrome.windows.create
, passing thetabId
. The tab will be detached from its previous window, and attached to the new window.
- Detect creation of tabs through
- You can rewrite the
window.open
method, which invokeschrome.tabs.create
andchrome.windows.create
to create a new popup window.
A global rewrite can be done by detecting page loads usingchrome.tabs.onUpdated
, withstatus=="complete"
, then usechrome.extension.getViews
to change thewindow.open
method. Make sure that you create a cached version of thewindow
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 ;)
来源:https://stackoverflow.com/questions/9871327/can-a-chrome-extension-change-chrome-settings-open-in-new-window-popup