Hello,
I'm currently trying to write a gnome shell extension. I would like to get the screenshot of a web page as a png file. To serve this purpose, I tried to get the Gdk.Pixbuf of the WebView window, in order to call savev... (the widget in the following code excerpt is indeed a WebKit.WebView):
const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
const WebKit = imports.gi.WebKit;
...
function save_as_png(widget)
{
let allocation = widget.get_allocation();
let wdw = widget.get_parent_window();
global.log(wdw); // (1)
global.log(allocation.width); // (2)
global.log(allocation.height); // (3)
let pixbuf = Gdk.pixpuf_get_from_window(wdw,0,0,allocation.widt h,allocat ion.height);
global.log(pixbuf); // (4)
}
when calling my extension, the logs (1),(2) and (3) are displayed on the gjs error console, but the (4) is never called. So I suspect that something has gone wrong...
how should I do in order to get the pixbuf right ?
In profond despear, I tried an alternative solution, by creating a cairo surface and context for my web view, hoping somehow that I would be able to call a write_to_png method from the surface. I did not succeed, in case someone would be pretty fit in on the subject, I write a buggy excerpt of what I tried :
let allocation = widget.get_allocation();
let wdw = widget.get_parent_window();
let surface = Cairo.image_surface_create(0,allocation.width,allo cation.height);
let crt = Gdk.cairo_create(wdw);
and then :
surface.write_to_png("/home/bluebird/tst.png");
or :
let pixbuf = Gdk.pixbuf_get_from_surface(surface,0,0,allocation .width,allocation.height);
This did not lead to the hoped success, and subsequents logs were not shown.
Any way, if anyone has any lead on the subject, this will be greatly appreciated.
Thanks for reading..
Nicolas