safari-extension

Redirection Before Page Load

I have an injection script--a start script--whose ultimate goal is to redirect to a different URL. That injection script needs to access the extension settings, so it sends a message to a global HTML file. That global file checks the settings and redirects to the appropriate URL by setting the safari.application.activeBrowserWindow.activ...

Google Reader Subscription URL

I'm trying to create a link that allows a user to subscribe to a feed directly in Google Reader (bypassing the iGoogle option). I've tried several target URLs: http://www.google.com/reader/view/feed/feed-url http://www.google.com/ig/addtoreader?feedurl=feed-url Each seems to work as expected most of the time, but I've bumped into a c...

Safari 5.0 Extension Scripts Won't Run on Local Files

Hi, I wrote a very simple extension for Safari 5 that only outputs a single log message from a start script. This is the start script: console.log('start script running'); If I go to any internet page (eg. http://www.yahoo.com) the log message appears in the error console. But if I open any local html page no log message appears. By l...

What does visibleContentsAsDataURL exactly do?

I am currently trying to build my first Safari extension. The SafariBrowserTab Class has a Method called "visibleContentsAsDataURL". I don't exactly understand what it does and can't get it to work. The docs just say: "Returns a data URL for an image of the visible contents of the tab." What does it mean? That I get the URL of a scre...

Can a Safari Extension react on the creation of a new tab?

I am currently writing my first extension for Safari 5. I can't find a reference on what events an extension can react. I want my extension to react on these events: when a new tab is created. when a new browser windows is created. when the URL inside a tab changes. Is this possible? ...

Safari Extentions: Event for tab change?

I'm trying to have a popup over a page in Safari which is tab-specific, and triggered by a button (which can visibly toggled). How can I ensure that when a tab is switched to, the button will be correctly toggled, i.e. highlighted if the popup is visible; not otherwise. I looked around for a "tab switch" kind of event to listen for but ...

Automatic Reload on Install

Hey there! When a script is injected in a safari extension it runs on page load, so that means when an extension is installed the injected javascript will only apply to newly-opened pages or pages which are reloaded afterwards. Does anyone know how to ensure the javascript is run without having to reload? Alternatively, forcing users t...

Downloads & Safari Extension

Hi, I wrote an application that runs in the background and periodically scans my download folder and moves files to different folders based on their type. I want rewrite this application as a safari extensions, but I didn't find a way to intercept downloads. All in all the ExtensionAPI seems to be very limited and seems to focus a lot o...

Safari, JavaScript and Copying to the System Clipboard

I'm doing a Safari extension and would like it to copy something to the users clipboard. Unfortunately all the sources I find talk about cross-platform solutions with Flash or have vague references to execCommand. Is there a way to do it in Safari with JavaScript? ...

-webkit-transform CSS Properties Hose Font Rendering

This question is pretty much the same as this one except that I'm seeing it exclusively in Safari on Mac (the only platform I need to care about). It's definitely CSS-related and I think I've narrowed it down to a few properties which seem to wreak havoc on the way text is rendered. They are: -webkit-transform-style: preserve-3d; -webki...

Open window with specified width & height

Hi, I am developing a safari extension and I need to create a popup once you click on a button, I tried an overlay with an iframe but, the destination redirects the whole page so I am forced to use a popup. "window.open() JavaScript method cannot be used to open a new tab and widow from a global HTML file or an extension bar. Instead, ...

How can I build a Safari extension package from the command line?

Instead of going to Extension Builder > Build Package…, I'd like to built a .safariextz package from the MyExtension.safariextension folder. I know I can unpack an extension with xar -xf. I suspect the way back involves packing it with xar, but then I'll need to do the code signing thing, which may or may not involve codesign(1). ...

Referencing a method within an object in JavaScript

In JavaScript, what is the proper way to reference an object's method within the object itself? I'm messing around with Safari Extensions, and I'm trying to make an extension that changes the background color of a div based on the extension's settings. I'm using the following code: function SwapColors() { this.bgColorMe = safari.exte...

How can I run a PHP script with cURL code in a Safari extension?

I am trying to run a PHP bot function in a Safari extension. This is the HTML code I've tried to put together, but it's a mess of PHP, cURL, and HTML, and I don't really know what I'm doing. I've never attempted to use cURL before I got this code from http://www.barattalo.it/2010/08/09/send-push-notification-to-iphone-with-php-and-push...

Wait for message to send in window.onbeforeunload?

I'm messing around with Safari extensions, and I'd like my extension to respond to the user opening or closing tabs. I have the extension injecting a script that runs when the new tab opens and notifies the global page that there's a new tab open. I want the script to also notify the global page when the tab closes. To do this, I'm havi...

How do I recognize a mouseclick in a webpage from a Safari extension?

I'm a bit of a noob, but I tried all of the obvious things. Perhaps my javascript is just terrible and that's why, but onmousedown = func; doesn't work. etc. function performCommand(event) { /*removed*/ //It reaches this point document.body.onclick = function() { //Never reaches this point /*removed*/ } } ...

jQuery access table inside a frame

Hi, I've got a problem. I want to select an element inside a frame (not iframe). The name of the frame is main, but I can't add an ID (complicated to explain, but not possible). How can I manipulate the data inside that frame? I already tried various different things (also from stackoverflow) but they didn't work... dodo frameset: <...

Safari extension settings

Hi, I'm building a safari extension... I need to get some settings, but, messages are asynchronous, so, if I query the global page for some settings, it isn't there right away... How can I solve this?? Global page (the message is received by the injected JS script) <!DOCTYPE HTML> <html> <script language="javascript"> func...

Safari extension message to injected.js

Hi, I try to send a message from to global page to my injected.js on the moment that a setting changes: global.html function settingChanged(event) { if(event.key == 'open') { safari.self.tab.dispatchMessage('openChanged', safari.extension.settings['open']); } } safari.ex...

Safari 5 Extension: How can I detect when a window's current tab has changed?

I have a Safari 5 extension that contains a toolbar. Whenever the current tab changes, that toolbar should be updated. I would like to do something like this from my bar's script: safari.self.browserWindow.addEventListener("activeTab", tabChanged, false); However, that doesn't seem to work. I have tried a number of other event names a...