You can use the "special" canLoad
message. Technically, it's intended to send a message and return a value related to whether an element on the page can load, but it's really just a synchronous message that's answered by the global HTML page the same way as any other. You'd just look for the message named 'canLoad'
instead of passing a custom message name:
// injected script
var myVar = safari.self.tab.canLoad( event );
// global HTML file
<!DOCTYPE html>
<script type="text/javascript" charset="utf-8">
safari.application.addEventListener( 'message', listen, true );
function listen( msgEvent ) {
switch( msgEvent.name ) {
case 'canLoad':
msgEvent.message = 'My return value';
break;
}
}
</script>
You can read more about the canLoad message in the development guide.