Extension for open non openable links in new tab

92 views
Skip to first unread message

Norbert K.

unread,
Jun 27, 2023, 10:43:50 AM6/27/23
to Chromium Extensions
Hi, Is there any extension that allows to open in new tab links that won't open in new tab normally? Like if you go to  Google Contacts and want to click on "pencil" to edit contact, but you can't open it in a new tab, you can only left click it, and it will edit on the same tab. If I want to open few of my contacts for example and edit them, not go back, swipe throu the list again to search for next one etc. 

Stefan Van Damme

unread,
Jul 7, 2023, 2:23:42 PM7/7/23
to Chromium Extensions, Norbert K.
Hi Norbert,

A Chrome extension can not change this open-link experience. That is the design of the Google Contacts website.
It is a good idea to provide feedback to the Google Contacts team so they can improve this experience. Click on the question mark icon in Google Contacts and select the "Send feedback" option from the menu.

Thanks,

wOxxOm

unread,
Jul 8, 2023, 12:37:37 AM7/8/23
to Chromium Extensions, Stefan Van Damme, Norbert K.
An extension can rather easily change this behavior because the resultant URL actually works when opened in a new tab manually, which means you can write an extension that overrides the `click` event on this UI element and then opens a new tab either using window.open (may be blocked) or by sending a message to its background script (service worker), which will use chrome.tabs.create({url: message.url, index: sender.tab.index + 1})

You can also do this in a userscript, where you'd use window.open or GM_openInTab.

Here's a basic example:

window.addEventListener('click', e => {
  const el = e.target.closest('[aria-label="Edit contact"]');
  if (el) {
    e.stopPropagation();
    window.open(`/person/${el.closest('[data-id]').dataset.id}?edit=1`);
  }
}, /* capture */ true);

Norbert K.

unread,
Jul 8, 2023, 5:44:48 AM7/8/23
to Chromium Extensions, wOxxOm, Stefan Van Damme, Norbert K.
How to do that exacly?

Max Nikulin

unread,
Jul 10, 2023, 2:02:47 AM7/10/23
to chromium-...@chromium.org
On 08/07/2023 11:37, wOxxOm wrote:
> An extension can rather easily change this behavior because the
> resultant URL actually works when opened in a new tab manually, which
> means you can write an extension that overrides the `click` event on
> this UI element

Is it intentional that listeners added by extensions have lower priority
than listeners added by pages when content scripts are injected by
scripting.executeScript? The consequence is that events are not
available for extensions when pages do

window.addEventListener(evName, e => {
e.stopImmediatePropagation();
e.preventDefault();
// do something else
}, { capture: true });

An extension may declare "content_scripts" "run_at" as "document_start",
but when a script is executed in response to user action,
injectImmediately is not a rescue since it requires page reloading.

Formally it is correct since extensions add their listeners after the
page, but it makes extensions less powerful.

wOxxOm

unread,
Jul 10, 2023, 2:45:47 AM7/10/23
to Chromium Extensions, Max Nikulin
Listeners added by an extension follow the DOM/HTML5 specification, there's no special mechanism to control precedence. If such a thing is to be added it should be proposed in https://github.com/w3c/webextensions/issues however it probably won't be accepted because web pages don't normally use a capturing event listener on `window`, AFAIK. Note that it'd be wrong to just switch the precedence for all extensions unconditionally because it'll break many extensions which need to react to changes made by a web page in order to augment them.
Reply all
Reply to author
Forward
0 new messages