Getting Safari document title/location with Scripting Bridge does not work in full-screen mode

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-03-10T12:35:09Z Indexed on 2010/03/13 9:35 UTC
Read the original article Hit count: 398

Filed under:
|
|

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.

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" and full-screen Safari windows.

Can anyone see what is wrong with the Scripting Bridge code below to cause it to fail for full-screen Safari windows?

Here the code (I omitted error checking for brevity):

AppleScript:

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

Scripting Bridge:

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);

Scripting Bridge error (with added line breaks):

  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 = <SBObject @0x175c2de0: 
                   currentTab of SafariWindow 0 of application "Safari" (238)>;
    }

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?

Any suggestions are greatly appreciated. Thanks!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about safari