Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:23:30+00:00 2026-06-06T13:23:30+00:00

I use Imager::Screenshot in my Perl code and it does work and takes the

  • 0

I use Imager::Screenshot in my Perl code and it does work and takes the screenshot.

Now, every time the browser opens in different position, meaning starting x and y positions might not be the same.

Is there a way to screenshot starting from the browser instead of the desktop starting position.

And if not (kind of off topic from programming) is there a way to set the browser open only in full size, no matter what program its opened from. Opened by user when clicked on the icon, or opened by Perl using Win32::OLE module.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:23:32+00:00Added an answer on June 6, 2026 at 1:23 pm

    You can use Win32::GuiTest::FindWindowLike to find the window handle associated with the browser and specify that to screenshot:

    #!/usr/bin/env perl
    
    use strict; use warnings;
    use Const::Fast;
    use Imager;
    use Imager::Screenshot qw( screenshot );
    use Win32::GuiTest qw( FindWindowLike SetForegroundWindow );
    
    const my $TYPE => 'bmp';
    
    my @windows = FindWindowLike(0,
        '(?:Mozilla Firefox)|(?:Internet Explorer)|(?:Opera)'
    );
    
    for my $hwnd (@windows) {
        warn "$hwnd\n";
        SetForegroundWindow $hwnd;
        sleep 1;
        my $img = screenshot(hwnd => $hwnd, decor => 1);
        die Imager->errstr unless $img;
    
        $img->write(file => "$hwnd.$TYPE", type => $TYPE)
            or die $img->errstr;
    }
    

    The code above will take separate screenshots for the overall IE window and the child window that holds the current tab. If you are only interested in top level IE windows, you’d want to use my @windows = FindWindowLike(0, 'Internet Explorer', '^IEFrame');

    In addition, if you have opened an “InternetExplorer.Application” window using Win32::OLE, you can access the object’s Top, Height, and Width properties to determine its location and area. In addition, you can get its HWND so that you can set it as the foreground window.

    #!/usr/bin/env perl
    
    use strict; use warnings;
    use Const::Fast;
    use Imager;
    use Imager::Screenshot qw( screenshot );
    use Win32::GuiTest qw( SetForegroundWindow );
    use Win32::OLE;
    $Win32::OLE::Warn = 3;
    
    const my $TYPE => 'bmp';
    
    const my $READYSTATE_COMPLETE => 4;
    
    my $browser = Win32::OLE->new("InternetExplorer.Application");
    $browser->Navigate('http://www.example.com/');
    
    sleep 1 while $browser->{ReadyState} != $READYSTATE_COMPLETE;
    $browser->{Visible} = 1;
    
    my $hwnd = $browser->{HWND};
    SetForegroundWindow $hwnd;
    sleep 1;
    
    my $img = screenshot(hwnd => $hwnd, decor => 1) or die Imager->errstr;
    
    my $title = $browser->{LocationName};
    $browser->Quit;
    
    $title =~ s/[^A-Za-z0-9_-]/-/g;
    $img->write(file => "$title.$TYPE", type => $TYPE) or die $img->errstr;
    

    Alternatively, using OLE events:

    #!/usr/bin/env perl
    use strict; use warnings;
    use feature 'say';
    use Const::Fast;
    use Imager;
    use Imager::Screenshot qw( screenshot );
    use Win32::GuiTest qw( SetForegroundWindow );
    use Win32::OLE qw(EVENTS valof);
    $Win32::OLE::Warn = 3;
    
    const my $TYPE => 'bmp';
    const my $READYSTATE_COMPLETE => 4;
    
    my ($URL) = @ARGV;
    die "Need URL\n" unless defined $URL;
    
    my $browser = Win32::OLE->new(
        "InternetExplorer.Application", sub { $_[0]->Quit }
    );
    Win32::OLE->WithEvents($browser, \&Event, 'DWebBrowserEvents2');
    
    $browser->{Visible} = 1;
    $browser->Navigate2($URL);
    
    Win32::OLE->MessageLoop;
    Win32::OLE->SpinMessageLoop;
    
    $browser->Quit;
    sleep 3;
    
    sub Event {
        my ($browser, $event, @argv) = @_;
        say $event;
    
        if ($event eq 'DocumentComplete') {
            $browser->{ReadyState} == $READYSTATE_COMPLETE
                or return;
    
            my $hwnd = $browser->{HWND};
            SetForegroundWindow $hwnd;
    
            my $img = screenshot(hwnd => $hwnd, decor => 1)
                or die Imager->errstr;
    
            my $url = valof( $argv[1] );
            $url =~ s{^https?://}{};
            $url =~ s{[^A-Za-z0-9_-]}{-}g;
    
            $img->write(file => "$url.$TYPE", type => $TYPE)
                or die $img->errstr;
    
            Win32::OLE->QuitMessageLoop;
        }
        return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: use Imager::Screenshot 'screenshot'; my $img = screenshot(hwnd => 'active',
I use the following code to get a screenshot of the screen and save
I'm trying to use use code get a screenshot in Mono C# but I'm
I use ffmpeg to capture screenshot from video. Here is the command code: ffmpeg
I use this code to make a screenshot, CGFloat breed = 768; CGFloat hoogte
I'm trying to use ScrollView with an ImageView in it. My xml code for
I am trying to use libjpeg to save a screenshot from an opengl buffer.
I'm trying to use facebook within my App by posting a screenshot of my
i have been trying to get a screenshot lately but every thing in vain
Is it possible to use Java to get a screenshot of an application external

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.