I - How to make the code work?
The code provided won't start. So here are two little tweaks.
1 - The common structure of bookmarklets is called IIFE-construction, i.e. Immediately Invoked Function Expression:
javascript:(function () {
/*code here*/
})();
2 - The second thing is the encoding, like %27%
etc, that's why the code won't trigger.
So the right code might be:
javascript:(function () {
window.open('https://www.webpagetest.org/?url='+window.location.href, '_blank')
})();
Now the code works, it "opens a webpagetest.org, fills the current page's url into the url field" filled with window.location.href
, or the URL you are at, the moment you trigger the code.
But it won't press the Start Test
button at the open page.
II - How to press Enter
at the page opened with a bookmarklet?
The answer: You cannot do it with bookmarklet. For at least due to two reasons.
The main reason is that you wish to press start test
button after opening this new page, but JS (in a stardard way) works only with one web-page. You might need some other tools.
And the second reason is that the site-builder has made it work this way. Moreover, the site may ask to solve captcha upon clicking the button.
III - Possible solution
That might exceed the scope of the question. But one of the possible ways to auto-trigger the button on exact site is some browser addon, e.g., tampermonkey or greasemonkey.
Strategy with the abovemenionned addon: Wait the page to load. Then if the site with the URL has a non-empty input with exact ID, then press button with an exact tagname
.
Apart from addon there might be some other ways though, depending on the goals.