Indeed this is weird. When I run your code, I get the Google consent modal, and an error
2 elements found for //body at pb11123357.pl line 13.
... most likely because there are two body elements, one in the consent modal iframe and one in the main page.
Once I click that away, I get the script content of the page, because the contents of script tags are also included in the textContent attribute. This is somewhat inconvenient, and I see no easy workaround for this. The fix seems to be to use the innerText attribute instead of textContent. Making this change makes the page "work" in the sense that the <script> content is not printed anymore. As a workaround you can monkey-patch the code until the next release:
use WWW::Mechanize::Chrome;
{
no warnings 'redefine';
sub WWW::Mechanize::Chrome::text {
my $self = shift;
# Waugh - this is highly inefficient but conveniently short to wri
+te
# Maybe this should skip SCRIPT nodes...
join '', map { $_->get_attribute('innerText') } $self->xpath('//bo
+dy', single => 1 );
}
}
Thanks for reporting this! If this works for you as well, I'll write a test for this and release the fix soonish. |