On Wednesday 14th of April at 9 am UTC, we will update Vivaldi's servers (see the time in your timezone). We expect it will take up to 12 hours. During this time there will be some downtime on the Forum, Sync and Community Blogs and Webmail. For status of the services, check https://vivaldistatus.com. Thanks in advance for your patience.

Restore Methods for chrome.tabs



  • What?
    An attempt to recover the methods lost in chorme.tabs after updating Vivaldi Snapshot 3.7.2202.3.

    List of methods:

    • getAllInWindow
    • getSelected
    • executeScript
    • insertCSS

    Demo

    1c3cee59-ff41-4cd7-a448-88c83822045c-image.png

    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 ^^

    alt text


  • Vivaldi Team

    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?


Log in to reply
 

Looks like your connection to Vivaldi Forum was lost, please wait while we try to reconnect.