Skip to content

performance issue with Page::getCurentUrl() #711

@divinity76

Description

@divinity76

I recently have to write shit like

        $currentUrl = $page->evaluate('document.location.href')->getReturnValue();
        // don't use getCurrentUrl() because it has a performance issue... don't have time to investigate now

because when I write

        $t = microtime(true);
        $currentUrl = $page->getCurrentUrl();
        $t = microtime(true) - $t;
        echo "\ngetCurrentUrl() took {$t} seconds." . PHP_EOL;

i sometimes often get crazy readings like

getCurrentUrl() took 0.46461796760559 seconds.
getCurrentUrl() took 2.9382970333099 seconds.
getCurrentUrl() took 4.4821469783783 seconds.

but when I write

        $t = microtime(true);
        //$currentUrl = $page->getCurrentUrl();
        // don't use getCurrentUrl() because it has a performance issue... don't have time to investigate now
        $currentUrl = $page->evaluate('document.location.href')->getReturnValue();
        $t = microtime(true) - $t;
        echo "\ngetCurrentUrl() took {$t} seconds." . PHP_EOL;

I consistently get fast readings like

getCurrentUrl() took 0.00039219856262207 seconds.
getCurrentUrl() took 0.00027704238891602 seconds.
getCurrentUrl() took 0.00028014183044434 seconds.
getCurrentUrl() took 0.00026392936706543 seconds.
getCurrentUrl() took 0.00025701522827148 seconds.

WSL Ubuntu 24.04 x86-64
chrome-php/chrome 1.14.0
chrome-php/wrench 1.7.1
php 8.4.12
Chromium 139.0.7258.138 snap

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions