Restore Methods for chrome.tabs
-
What?
An attempt to recover the methods lost inchorme.tabs
after updating Vivaldi Snapshot 3.7.2202.3.List of methods:
getAllInWindow
getSelected
executeScript
insertCSS
Demo
Installation
You can learn how to install here.- Note: Be sure to launch this code before any other mods.
Javascript:
/* * Restore Methods for chrome.tabs * Written by Tam710562 */ window.gnoh = Object.assign(window.gnoh || {}, { tabs: { getAllInWindow: function () { let windowId; let callback; Array.from(arguments).forEach(function (argument) { switch (typeof argument) { case 'number': windowId = argument; break; default: callback = argument; break; } }); chrome.tabs.query({ windowId: windowId || vivaldiWindowId }, function (tabs) { callback(tabs); }); }, getSelected: function () { let windowId; let callback; Array.from(arguments).forEach(function (argument) { switch (typeof argument) { case 'number': windowId = argument; break; default: callback = argument; break; } }); chrome.tabs.query({ active: true, windowId: windowId || vivaldiWindowId }, function (tabs) { const tab = tabs[0]; if (tab) { callback(tab); } }); }, executeScript: function () { let tabId; let details; let callback; Array.from(arguments).forEach(function (argument) { switch (typeof argument) { case 'number': tabId = argument; break; case 'object': details = argument; break; default: callback = argument; break; } }); if (tabId) { gnoh.webPageView.callMethod(tabId, 'executeScript', [details, callback]); } else { gnoh.webPageView.callMethod('executeScript', [details, callback]); } }, insertCSS: function () { let tabId; let details; let callback; Array.from(arguments).forEach(function (argument) { switch (typeof argument) { case 'number': tabId = argument; break; case 'object': details = argument; break; default: callback = argument; break; } }); if (tabId) { gnoh.webPageView.callMethod(tabId, 'insertCSS', [details, callback]); } else { gnoh.webPageView.callMethod('insertCSS', [details, callback]); } } }, webPageView: { getSelected(callback) { gnoh.tabs.getSelected(function (tab) { callback(this.get(tab.id)); }.bind(this)); }, get: function (tabId) { return document.getElementById(tabId); }, callMethod: function () { let tabId; let methodName; let args; Array.from(arguments).forEach(function (argument) { switch (typeof argument) { case 'number': tabId = argument; break; case 'string': methodName = argument; break; default: args = argument; break; } }); if (tabId) { const wpw = this.get(tabId); wpw[methodName].apply(wpw, args); } else { this.getSelected(function (wpw) { wpw[methodName].apply(wpw, args); }); } } } }); if (!chrome.tabs.getAllInWindow) { chrome.tabs.getAllInWindow = gnoh.tabs.getAllInWindow; } if (!chrome.tabs.getSelected) { chrome.tabs.getSelected = gnoh.tabs.getSelected; } if (!chrome.tabs.executeScript) { chrome.tabs.executeScript = gnoh.tabs.executeScript; } if (!chrome.tabs.insertCSS) { chrome.tabs.insertCSS = gnoh.tabs.insertCSS; }
Changelog
18/02/2021
- Create the first version.
-
@tam710562 Damn, did you just write your own api?
-
@luetage said in Restore Methods for chrome.tabs:
@tam710562 Damn, did you just write your own api?
I'm just lazy to re-update my old mods
-
@tam710562 Well, good job, it works. You just saved tabscroll ^^
-
A[nother] mod which fix mods. I've no [more] words
-
@luetage said in Restore Methods for chrome.tabs:
@tam710562 Well, good job, it works. You just saved tabscroll ^^
-
Note that getAllInWindow() and getSelected() are marked as deprecated and has been for a while, there should be no reason to continue using them.
-
@pettern True, but is there a chance we get the non‐deprecated apis back?
-
Why in the bloody nonsense insertCSS was removed?
-
tabs.executeScript
andtabs.insertCSS
are marked as deprecated on chrome developer page. I noticed this when trying to update an extension. The replacement isscripting.executeScript
andscripting.insertCSS
, but I couldn’t get it to work in Vivaldi for modifications. -
@luetage i tested with it and it is working
chrome.tabs.query({ active: true, windowId: vivaldiWindowId }, (tabs) => { const tab = tabs[0]; if (tab) { chrome.scripting.executeScript({ target: { tabId: tab.id }, function: () => { window.scrollTo({ top: 0, behavior: 'smooth' }); } }); } });
-
@tam710562 Thank you, you are right. I left the target out. Thought it would work with active tab like the old api. Anyway, this probably means people don’t need to install extra code anymore.
-
@luetage @tam710562 I'm slightly confused. So the mod still work, the original issue was fixed or the latest js snippet is the updated one?
-
@hadden89 This page doesn’t feature a mod, but a workaround to make deprecated apis work in other mods. This isn’t needed anymore, since the new chrome.scripting api seems to work.
-
@luetage What I thought. So my small experimental extension (colored scrollbars) is probably broken due the fix of the issue plus the recent changes. Seems I have (to try) to learn few chrome APIs now
-
This post is deleted!