5

I need to grab the current html inside a chrome packaged app. I am aware of Taking screenshot using javascript for chrome extensions but when I tried this, chrome states that the "tab" permission is not allowed for packaged apps.

Is there any way I can reliably grab the current page?

Community
  • 1
  • 1
rene_gr
  • 489
  • 4
  • 12

2 Answers2

1

You cannot do what you are trying to do with a packaged Chrome application. Instead, you should probably look at making an extension, as that would be the way to go if you want to interact with the current page.

If you're unsure, here's a resource for figuring exactly what you should choose: https://developer.chrome.com/webstore/choosing

Invictus
  • 181
  • 9
  • 1
    I have the same problem as rene_gr and I can't use extension since I need a webview (which is not supported in chrome extension API). – Le_Coeur May 08 '14 at 20:21
  • "Cannot do", is not entirely true. There is some "quirky" workaround which does what I want (almost). When you keep the caveats in mind, you can do the following: Convert the current html state to a canvas -> http://html2canvas.hertzen.com/, now you can convert the content of a canvas to an image resource. Now it is up to you, what you want to do with it. Hope this helps. – rene_gr May 09 '14 at 13:10
  • @rene_gr But that somewhat begs the question of why go to all that trouble - surely it would be easier to just make an extension to do this? – Invictus May 09 '14 at 18:33
  • @Invictus I do not intend to"extend" the browser. I am building a standalone software on its own, which just uses the chrome desktop platform for deployment. Deploying as an extension would be a missfit in that case. – rene_gr May 10 '14 at 20:32
  • @rene_gr I understand that - Google just calls that type of program an "extension". Packaged apps are designed to be isolated from even the web-page. Whether or not the names are particularly fitting is besides the point. – Invictus May 12 '14 at 11:47
1

Not from a chrome extension, as those are browser-centric solutions (not webpage-centric).

Niklas Von Hurtzen has created a very useful js extension called html2canvas that essentially does what you're looking for, just not as a chrome extension. You can see it here.

Once "rendered," the plugin will create a canvas element by traversing the DOM tree of whatever you hand to the extension. From there it's pretty simple... yourRenderedCanvasElement.toDataUrl() will return a data: URL representation of that canvas element, which by default is a PNG, giving you a "screenshot."

Edit: Ha, I see now that you reference this exact thing in the message thread in the other answer...

Foo
  • 158
  • 8