Safari screen.availWidth Times out

I’ve got this script I use often:

tell application "Safari"
	if (exists of document 1) is false then make new document
	set screen_width to (do JavaScript "screen.availWidth" in document 1)
	set screen_height to (do JavaScript "screen.availHeight" in document 1)
	set screen_height to (screen_height - 50)
	set screen_width to (screen_width * 0.6)
	set bounds of window 1 to {0, 0, screen_width, screen_height}
end tell

Last week I started getting time outs after a few minutes on the first javascript line. Did something change in Safari? I’m on Version 10.1.2 (10603.3.8)

Model: MacBook Pro 15" Retina
AppleScript: 2.4
Browser: Safari 603.3.8
Operating System: Mac OS X (10.10.5)

UPDATE: Just discovered another script that doesn’t work. Getting hung up on the do JavaScript part of it.


Just to narrow down the problem: What was the previous version of Safari you were using? Did you update it recently or did you wait for a very long time? I mean, Safari is updated 5 days ago.

It’s a long, long, long shot. But what happens if you disable and enable the option that Apple Events are allowed to execute JavaScript from the developer menu?

Thanks for the reply DJ

I get this:

error “Safari got an error: You must enable the ‘Allow JavaScript from Apple Events’ option in Safari’s Develop menu to use ‘do JavaScript’.” number 8

When I have this line in a script:

set screen_width to (do JavaScript “screen.availWidth” in document 1)

I get this error after a few minutes:

error “Safari got an error: AppleEvent timed out.” number -1712

Here’s another thing: Other “do Javascript” commands work fine. For example, filling out forms works great:

do JavaScript “'” & AccountName & “';” in document 1

I see that Safari updated on my system on July 21, which is right around the time I started noticing errors. Thanks for heads up about that. Now researching to figure out how to revert back to a previous version of Safari. Fun stuff.

Bummer, that didnt work either. Reverted to Version 10.1.1 (10603.2.5) same result