开发者

What does visibleContentsAsDataURL exactly do?

开发者 https://www.devze.com 2023-01-09 06:31 出处:网络
I am currently trying to build my first Safari extension. The SafariBrowserTab Class has a Method called \"visibleContentsAsDataURL\".

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开发者_Go百科: "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!


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."


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号