views:

53

answers:

2

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 screenshot of the tabs' content back? Can someone explain me?

Thanks!

+2  A: 

I think it returns what is effectively a screenshot of the tab. The format is explained here http://en.wikipedia.org/wiki/Data_URI_scheme

According to Apple's Safari reference documentation the return value is "a base-64 encoded PNG."

paulgrav
A: 

A data URL is a specal type of url basically consisting of a mimetype and data, in the case of png you'll get something along the lines of:

data:image/png;base64;lotsofstuff

You can then do whatever you want with it (it's just a string), or if you want to display the content:

img = new Image();
img.src = someTab.visibleContentsAsDataURL();
someElement.appendChild(img);

or

someCanvasContext.drawImage(img);

etc

olliej