Time to Load Internet Pages

Hey :slight_smile: I'm using a macro to search an internet page using regular expression but the page is taking more or less time to load depending on network quality. When i do a pause of 3 seconds for example sometimes it's too long because the page has loaded after only 1 second and sometimes not enough because it copies the page and start the regular expression search before the page has finished loading.

Is there a command such has wait for the page to finish loading?

Or is there a way to say that if the regular expression is failing finding results wait another second and copy/serach the page again?

2nd solution might be better because i don't need all of the page to load like the ads..

Thanks for your help :smile:

If this is one site you're visiting repeatedly, you might enable automatic Reader View for it.

Probably the simplest approach is to wait for the page to load and then invoke a Get URL for the %SafariURL%, saving that to a variable you then process with your regex.

But that's the problem: how long to wait?

The Get URL action is independent of whatever is currently in the browser, so it doesn't matter if you have reader view enabled. In my experience this action always returns the entire raw contents of the URL - there's no having to wait for it to finish. I use this action extensively to avoid having to use the browser and so I'm able to process web pages in the background. It's more difficult having to use regex etc on raw HTML but it means I can use my Mac for other stuff while it's processing.

A search of this forum, by the way, for "safari wait" returns a number of discussions of this problem. The action Wait for Browser to Finish Loading (actions:Wait For Browser to Finish Loading [Keyboard Maestro Wiki]) was broken as of Safari 12.1...

I was assuming the OP is browsing. But if the macro is just going through a list of URLs, that approach would not be relevant of course.

ty very much :pray: I'm going to have a go at that get url action that seems promising and come back to you in case of difficulties.

1 Like

I don't know of a built in Keyboard Maestro way, but this seems like the perfect thing for a custom macro.

Wait for page to be ready.kmmacros (4.1 KB)

Note that the 'JavaScript in Safari' action represents however you're getting the contents of the webpage to test it for your regex result. You can write in some JavaScript to query the page or replace it entirely with whatever actions you currently use to get your regex. You just need to set the RegexResults variable so you can check it in the following If action

1 Like

brilliant ty :grinning:

1 Like