JingMatrix / ChromeXt

UserScript and DevTools supports for Chromium based and WebView based browsers
https://jingmatrix.github.io/ChromeXt/
GNU General Public License v3.0
700 stars 39 forks source link

Implement window.close() #180

Closed JPisaBrony closed 3 months ago

JPisaBrony commented 3 months ago

I was trying to use the function window.close() but it doesn't seem to work. below is some example code that I used to test it (the example code just adds a button under the google image logo on google.com that is clickable). I also tried to use unsafeWindow but that has the same results. The example code does work on firefox mobile under tampermonkey but doesn't on chrome using ChromeXT using the latest version from the github actions.

  // ==UserScript==
  // @name         Window Testing
  // @namespace    http://tampermonkey.net/
  // @version      1.0
  // @description  Window Testing
  // @author       JP
  // @match        https://www.google.com/
  // @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  // @grant        window.close
  // @grant        unsafeWindow
  // ==/UserScript==

  (function() {
      'use strict';

      var buttonClick = (element) => {
          console.log("button clicked");
          window.close();
          unsafeWindow.close();
      }

      var button = document.createElement("button");
      button.innerHTML = "Button";
      button.onclick = buttonClick;
      var img = document.getElementById("hplogoo");
      img.append(button);
  })();
JingMatrix commented 3 months ago

Yeap, it is not supported yet. Would you please tell me why you need this API? So that I could be convinced to implement it.

JPisaBrony commented 3 months ago

my current use case for it was something similar to the "OneTab" plugin. (it is basically a plugin that takes all of the browser tabs and puts them into one tab by taking the url of each tab and putting it into a list on a single page). I was using a button to send some information off to a server and then closing the page after (assuming I got a 200 back from the server).

JingMatrix commented 3 months ago

I have implemented this API for Chrome and Edge browsers, you may start trying it.