0

I made some scripts to automatically insert the username and password and press the Log in button for me when I visit websites. On some websites, it is as easy as

document.getElementById('username').value='myname'
document.getElementById('loginButton').click()

And when I visit the website, all those actions will be done instantly. However, on some websites, such as https://login.payoneer.com/, the script doesn't run at all. When I paste the script into the console, it works fine; however, it doesn't automatically run when the page loads. Can someone suggest a way to make the script work? This is my script:

// ==UserScript==
// @name         payoneer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://login.payoneer.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=payoneer.com
// @grant        none
// @run-at document-start
// ==/UserScript==

(function() {
     window.onload = function (){
         function replaceValue(selector, value) {
  const el = document.querySelector(selector);
  if (el) {
    el.focus();
    el.select();
    if (!document.execCommand('insertText', false, value)) {
      // Fallback for Firefox: just replace the value
      el.value = 'new text';
    }
    el.dispatchEvent(new Event('change', {bubbles: true})); // usually not needed
  }
  return el;
}
replaceValue('#username',"myUsername@gmail.com");
    document.getElementsByClassName('text-box__input')[1].setAttribute("id","passworde");
    replaceValue('#passworde',"MyPASsword123!")


     }
    'use strict';

    // Your code here...
})();
Randy VU
  • 59
  • 1
  • 1
  • 7
  • Related: [How to change the value of an input field](https://stackoverflow.com/questions/72871226/how-to-change-the-value-of-an-input-field) and [Enter data into a custom-handled input field](https://stackoverflow.com/questions/57879322/enter-data-into-a-custom-handled-input-field)? – ggorlen Jul 05 '22 at 18:59
  • Auto-writing value works fine for me. This website just deletes everything you write into the input field after a few milliseconds. – Konrad Jul 05 '22 at 19:05
  • I managed to input the text into the input field and keep it there. What I can't do is make the script run by itself when the page loads. – Randy VU Jul 05 '22 at 21:52

1 Answers1

0

In my experience it's usually a problem with timing (waiting for the page to completely load before running the script). I'd take a closer look at:

  • if your script is running, but coming across an error before being able to run entirely. If so, I'd take a look at solutions that other community members have come up with.
  • if your script really doesn't run at all, maybe check your tampermonkey or browser settings

at the very leaast, by debugging the above, you can come up with a better idea on the source of the problem

ad2969
  • 440
  • 3
  • 7
  • I think so too. However, I tried all those solutions, but they don't work. – Randy VU Jul 05 '22 at 21:50
  • Is it that your script doesn't run at all? – ad2969 Jul 06 '22 at 03:18
  • yes, it doesn't run at all, and I don't know why as it runs normally when entered in the console – Randy VU Jul 06 '22 at 04:34
  • If you are using Tampermonkey, you can try to restart Tampermonkey, that has solved similar problems for me: Go to Tampermonkey Dashboard, then Settings tab, scroll down, the last button is "Restart Tampermonkey" – cuzi Jul 06 '22 at 08:10
  • Yes, if it is not running at all, it might not be a problem with your code itself, but with your browser/tampermonkey. Your script configs given also look ok to me – ad2969 Jul 07 '22 at 20:16