A simple login script sometimes work and sometimes doesn't - userscripts

I have the following code I execute in Chrome with Tampermonkey, which I use to login to digitalocean.com.
setTimeout (function() {
document.querySelector("input[type=submit]").click();
}, 3000);
For some reason, this code sometimes work and sometimes it doesn't: That is, sometimes I'm logged in and sometimes (most cases) I get DigitalOcean's 404 webpage.
My login details are already saved in local storage and appear on the form.
By principle, this problem can be reproduced by registering to DigitalOcean, installing Tampermonkey, and executing the code with it, with the match:
https://cloud.digitalocean.com/login*
Might something be missing to ensure human-like behavior in the eyes of the machine?

OK, it took some digging, but I see what's going on.
There is an authentication token in the form.
If the token is not what the server expects, it kicks you to a 404 error at https://cloud.digitalocean.com/sessions.
If your browser loads the login page from cache (usually because you got to it by clicking the "back" button in your browser) you'll be submitting an invalid token (the one you got back when the page was put in the cache).
Sometimes it's wrong for some other reason I haven't figured out.
To deal with the cache-loaded page issue
I'd edit your script check if the page was loaded from cache, and refresh the page instead of triggering the click event:
if (window.performance.navigation.type === 2)
{
location.reload();
} else {
document.querySelector("input[type=submit]").click();
}
The other issue is probably an issue with DigitalOcean's back-end
I'd recommend that you report the fact that their login page seems to occasionally get a bad authentication token, as the issue can intermittently be reproduced by clicking (with the mouse) on the "Log In" button of a freshly loaded copy of the page.
(I wouldn't mention the script or they'll blame it and then you'll be out of luck.)
In the mean-time
As a stop-gap until they fix their issue, you could make a new script matching https://cloud.digitalocean.com/sessions (it sends me to that page exactly, but add a * if it's needed) that sends you back if you came from the login page, and got a 404 error:
if (document.referrer.startsWith("https://cloud.digitalocean.com/login") && document.title.endsWith(" (404)"))
{
history.back();
}
Note that document.title.endsWith(" (404)") only works because the contents of their 404 page's <title> tag ends with (404).

It seems to be a bug in Tampermonkey as the reported behavior doesn't happen in Greasemonkey.
Anyway, 3D1T0R's answer provides an interesting workaround with the current situation (would thumb up if I could).

Related

Why does my iframe sometimes initially load the Return URL page before the DocuSign form has been signed?

For my Next.js application, I'm embedding a DocuSign form using an iframe. At times when I visit the page where that form exists, I'll sometimes see the Return URL page (which I should only be redirected to in the iframe after having signed the form) when the page initially loads. After a few seconds, the correct page with the form loads in the iframe.
This issue does not occur when first visiting the form page. This typically happens after I return to home page (or visit any other page) without having signed the form and then return to the form page. Has anyone else who worked with embedding DocuSign forms using an iframe experienced this issue? If so, could you please explain how you were able to resolve it?
It's possible the envelope is locked. Instead of getting an error you get redirected back.
Normally, that will happen when you already signed.
It's also possible the URL you generated has expired. You have to generate it when the user click, not ahead of time, it expires within a few minutes.
Using an iframe can cause problems. What is the reason you use an iframe?

Netlify Page Not Found/White Page

I have been trying to figure out Netlify redirects. My Netlify app is at this link (however this is a blockchain application and requires that you have metamask, so I will try to explain my problem so that you don't have to install it to actually answer my question): rekt.netlify.app
I have two main problems:
I have already tried the whole _redirects file with /* /index.html 200 in it. This works when I go to rekt.netlify.app/games and refresh, it will actually come back to that page. That's good. The issue is when I then go to rekt.netlify.app/games/Valorant for example, it will be a white page on refresh, and I cannot figure out why. In my react application, I have react router set up so the path is path="/games/:game"
I went to the Networks tab in the google inspect and I found that this was the request URL when I refresh the page on /games/Valorant: https://rekt.netlify.app/games/static/css/2.80dce9aa.chunk.css
As you can see, the issue is probably something to do with that /games/ comes before /static/ in the URL. I'm a beginner so I don't know what that actually means.
The second issue I am having is that, the img tags of the games load on the /games page, however, when you click on a specific game and attempt to go to a /games/Valorant for example the image will not load. I believe this is due to a similar problem. I have gone into Network tab of google inspect and when I look at the image being loaded in the /games page, it attempts to GET https://rekt.netlify.app/static/media/league_wallpaper.f5e6bf5f.jpg which works. However, when being loaded in the /games/Valorant page, it attempts to GET https://rekt.netlify.app/games/static/media/league_wallpaper.f5e6bf5f.jpg and this does not work, it's a blank page.
You can notice that the second link there has /games/ in it which I believe is preventing it from getting the image. Potentially the problem here is that anything more than one / in the URL is messing things up? I'm not sure. This is the link to my github project: https://github.com/jacob-tucker/ReKt
Edit: Here are some screenshots that will hopefully help. This first one shows that the request URL is trying to get the image from /games/static (which I don't think makes sense). This is happening on the /games/Valorant page.
And then here is a screenshot of /games/Valorant trying to load as well after I refresh the page and get a blank white screen (it returns a status code of 200 because I have /* /index.html 200 in my _redirects file.
I had a the same issue a while ago, I've just added
"homepage": "https://my-app.netlify.app",
in package.json and it worked perfectly.

"WebExtension::executeScript: content script injected VM149:1" in Chrome loading React app

Haven't come across this message in all our testing and not sure if it is related to the actual issue.
Basically, have a user agreement text box that the user has to "read" (scroll to the bottom of) before they can click the box that they agree to it. Pretty standard stuff. We launched the web app Sunday and of about 100 users, two have stated that even though they scrolled to the bottom of the text box, the box did not become clickable.
The first one never got back to me, but the second user did and sent me a screenshot of the console:
WebExtension::executeScript: content script injected VM149:1
They are indeed scrolling to the bottom of the box. Initially, we just thought they were scrolling to the bottom of the page and they thought that is what they needed to do. But we were wrong.
I can't find much on it. Not even sure if it is related to the issue since it wasn't labeled as an error.
Both users are using Chrome latest version on Windows. We have them try Edge or Firefox and it works fine. Seems to be isolated to Chrome.
This is likely to be the Okta browser plugin. I have it installed and it produces this same error. The source of the plugin script is:
(function(code) {
if (eval("typeof Okta === 'undefined'")) {
eval("window.Okta = {};");
eval(code);
console.log("WebExtension::executeScript: content script injected")
} else {
console.log("WebExtension::executeScript: skipping eval script")
}
}
)(" /* A LOT OF MINIFIED CODE HERE */ ");

Robot Framework Click Button vs Submit Form

I'm new to Robot Framework and stuck with quite simple login web page test using SeleniumLibrary:
*** Test Cases ***
Valid Login
Open Browser To Login Page
Input Username admin
Input Password test
Submit Credentials
Dashboard Page Should Be Open
[Teardown] Close Browser
Most of the keywords are irrelevant to the question, except
Submit Credentials
Click Button login-button
Dashboard Page Should Be Open
Location Should Be ${DASHBOARD URL}
Title Should Be Dashboard
If I run this test, it will fail, because Location Should Be check is executed too early, while browser is still on the original login page. I found two solutions that work, but both seems to be conceptually wrong:
Use sleep
Submit Credentials
sleep ${DELAY}
Dashboard Page Should Be Open
In this case ${DELAY} should be quite big (e.g. 10s) to be sure that page is definitely loaded or it may fail anyway. Also, I've read that best practice is to avoid sleeps. And I can't use some Wait Until Page Contains, because I don't know, whether login page will be loaded again with some error message or Dashboard page loaded in success.
Use Form Submit instead of Click Button:
Submit Credentials
Submit Form login-form
The Form Submit works fine, but it's different from actually clicking a button, because button may have some onclick handler that would prevent submitting a form.
Using Wait Until Keyword Succeeds as suggested in some other threads doesn't seem to help, as Click Button succeeds right away.
You definitely should not use sleep since it introduces artificial delays that may make your whole suite slower than it needs to be. I personally also thing Wait until keyword succeeds should almost never be used. It litters the log with messages as it retries. Plus, I think it masks problems instead of fixing them.
The answer is to use one of the wait keywords. You say you can't use Wait Until Page Contains ""because I don't know, whether login page will be loaded again with some error message or Dashboard page loaded in success". I don't understand that reasoning.
Your application should be deterministic. That is, if you enter correct login credentials than you should be guaranteed that it will go to the dashboard page, and if you enter the wrong conditions you should see an error and/or be redirected back to the login page.
The point of the test is to verify those conditions. So, for a test that verifies whether you get the dashboard page or not, you should find an element on the dashboard page and wait for it to be visible after submitting the form. If it doesn't appear in the proper amount of time, your test should throw an error.
Personally I recommend using page objects. The library I wrote [1], for example, has a mechanism to wait for a page refresh, and assertions to verify you are on the page you think you should be on. You don't need to use my library though -- the core of the code is only a couple hundred lines of code, so it's easy to write your own.
[1] https://github.com/boakley/robotframework-pageobjectlibrary

Add bug to Bugzilla via code

I'm using browser-like approach for adding a bug to Bugzilla.
I'm making a successful login. When I add the bug, I don't get error. I get status code OK. But, the response html contains this:
Bugzilla – Suspicious Action
"It looks like you didn't come from the right page (you have no valid token for the create_bug action while processing the 'post_bug.cgi' script). The reason could be one of:
You clicked the "Back" button of your web browser after having successfully submitted changes, which is generally not a good idea (but harmless).
You entered the URL in the address bar of your web browser directly, which should be safe.
You clicked on a URL which redirected you here without your consent, in which case this action is much more critical.
Are you sure you want to commit these changes anyway? This may result in unexpected and undesired results."
There is a confirm button.
When I do this by hand (not by code), I don't get the error page. Instead, I get response that everything went fine and I can get my bug's id. So, ahead in my code I'm using the id. However, because of the error I get, the id is an empty string. How to resolve this?
Can it be resolved by clicking on the confirm button by code?
You can use Bugzilla's REST API from your script.
Creation of a bug is documented here

Resources