Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Safari document title/location with Scripting Bridge does not work in full-screen mode
    text
    copied!<p>I'm trying to get the URL and document title from the topmost Safari document/tab. I have an AppleScript and an objective-c version using Apple's Scripting Bridge framework.</p> <p>Both versions work fine for most web pages, however when I open a Youtube video in full-screen mode, the Scripting Bridge based version fails. The Apple Script works fine for "normal" <strong>and</strong> full-screen Safari windows.</p> <p><strong>Can anyone see what is wrong with the Scripting Bridge code below to cause it to fail for full-screen Safari windows?</strong></p> <p>Here the code (I omitted error checking for brevity):</p> <p><em>AppleScript:</em></p> <pre><code>tell application "Safari" # Give us some time to open video in full-screen mode delay 10 do JavaScript "document.title" in document 0 end tell </code></pre> <p><em>Scripting Bridge:</em></p> <pre><code>SafariApplication* safari = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"]; SBElementArray* windows = [safari windows]; SafariTab* currentTab = [[windows objectAtIndex: 0] currentTab]; // This fails when in full-screen mode: id result = [safari doJavaScript: @"document.title" in: currentTab]; NSLog(@"title: %@", result); </code></pre> <p><em>Scripting Bridge error</em> (with added line breaks):</p> <pre><code> Apple event returned an error. Event = 'sfri'\'dojs'{ '----':'utxt'("document.title"), 'dcnm':'obj '{ 'want':'prop', 'from':'obj '{ 'want':'cwin', 'from':'null'(), 'form':'indx', 'seld':1 }, 'form':'prop', 'seld':'cTab' } } Error info = { ErrorNumber = -1728; ErrorOffendingObject = &lt;SBObject @0x175c2de0: currentTab of SafariWindow 0 of application "Safari" (238)&gt;; } </code></pre> <p>I could not find details about the given error code. It complains about 'currentTab' which shows that the JavaScript event at least made it all the way to Safari. I assume that the current tab receives the event, but refuses to run the JS code, because it is in full-screen mode. However, why does this work for an AppleScript? Don't they use the same code path eventually?</p> <p>Any suggestions are greatly appreciated. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload