Last active
December 22, 2015 03:29
-
-
Save BastienDurel/6410525 to your computer and use it in GitHub Desktop.
Trigger gerror bug in perl-gtk3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -CSD | |
use strict; | |
use warnings; | |
use Gtk3 -init; | |
use Gtk3::WebKit qw(:xpath_results :node_types); | |
use Data::Dumper; | |
use Carp; | |
$SIG{ __DIE__ } = sub { Carp::confess( @_ ) }; | |
die "Usage: $0 url_to_test" unless defined $ARGV[0]; | |
my $url = $ARGV[0]; | |
my $window = Gtk3::OffscreenWindow->new(); | |
$window->set_default_size( 1024, 1280 ); | |
# Build a WebKit frame | |
my $view = Gtk3::WebKit::WebView->new(); | |
$view->load_uri($url); | |
# Pack the widgets together | |
my $scrolls = Gtk3::ScrolledWindow->new(); | |
$scrolls->add($view); | |
$window->add($scrolls); | |
$window->show_all(); | |
my %RESOURCES; | |
$view->signal_connect('resource-request-starting' => sub { | |
my ($_view, $frame, $resource, $request, $response) = @_; | |
my $uri = $request->get_uri or return; | |
print STDERR "resource-request-starting: ", $request->get_uri, "\n" | |
if $ENV{DEBUG}; | |
if ($uri =~ /s7.addthis.com/) { | |
# don't download that ! | |
$request->set_uri('about:blank'); | |
print STDERR "REMOVED !\n" if $ENV{DEBUG}; | |
return; | |
} | |
return if $uri eq 'about:blank'; | |
print STDERR "pushed in RESOURCES\n" if $ENV{DEBUG}; | |
$RESOURCES{$uri} = \$resource; | |
}); | |
# Log errors | |
$view->signal_connect('resource-load-failed' => sub { | |
my ($web_view, $web_frame, $uri) = @_; | |
print STDERR 'resource-load-failed: ', Dumper(@_), "\n" if $ENV{DEBUG}; | |
} ); | |
# Get end of page loading | |
$view->signal_connect('notify::load-status' => sub { | |
return unless $view->get_uri and $view->get_load_status eq 'finished'; | |
print STDERR "notify::load-status -> finished \n" if $ENV{DEBUG}; | |
my $process_cb = sub { | |
eval { | |
# Do some work in browser, then exit | |
end_process(); | |
1; | |
} or do { | |
print "Error: ", $@; | |
exit 2; | |
}; | |
}; | |
Glib::Timeout->add(1000, sub { | |
Glib::Idle->add($process_cb); } ); | |
}); | |
# Start browser, collect data | |
Gtk3->main(); | |
# Now check data | |
# end program | |
exit 0; | |
############# | |
# Functions # | |
############# | |
sub end_process { | |
Gtk3->main_quit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ perl -CSD repro-gerror-bug.pl https://shop.icrc.org/health-care-in-danger-the-human-cost.html
GType GError (24358000) is not registered with gperl at /usr/share/perl5/Gtk3.pm line 137.
at repro-gerror-bug.pl line 9
main::ANON('GType GError (24358000) is not registered with gperl at /usr/...') called at /usr/share/perl5/Gtk3.pm line 137
Gtk3::main('Gtk3') called at repro-gerror-bug.pl line 89