Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Browser/BrowserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function dispatchEvent(string $eventName, array $params): void
if ('binding' === $eventName) {
$bindingName = $params['name'];
if (is_string($bindingName) && isset($this->bindings[$bindingName]) && is_callable($this->bindings[$bindingName])) {
if (!is_string($params['pageId'])) {
throw new ProtocolErrorException('Invalid pageId in binding event', 0);
}
$source = [
'context' => $this,
'page' => $this->pages[$params['pageId']] ?? null,
Expand Down
6 changes: 6 additions & 0 deletions src/Transport/JsonRpc/JsonRpcTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ private function handleEvent(array $event): void
}

$objectId = $event['objectId'];
if (!is_string($objectId)) {
$this->logger->warning('Invalid objectId in event', ['event' => $event]);

return;
}

if (isset($this->eventDispatchers[$objectId])) {
$this->logger->debug('Dispatching event to registered handler', [
'objectId' => $objectId,
Expand Down
12 changes: 11 additions & 1 deletion tests/Integration/Browser/BrowserContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@ public function itSetsGeolocation(): void

$page->click('button');

usleep(500000);
// Poll for either coordinates or error text since Page::waitForFunction is not available
$deadline = microtime(true) + 5.0; // 5 seconds
do {
$content = $page->content() ?? '';
$hasCoordinates = str_contains($content, '59.95,30.31667');
$hasError = str_contains($content, 'Error');
if ($hasCoordinates || $hasError) {
break;
}
usleep(100 * 1000); // 100ms
} while (microtime(true) < $deadline);

$content = $page->content();
$hasCoordinates = str_contains($content, '59.95,30.31667');
Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/Locator/LocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ public function itTakesAScreenshotOfAnElement(): void
$this->assertStringStartsWith(base64_decode('iVBORw0KGgo='), base64_decode($binary));
}

#[Test]
public function itEvaluatesElementTagNameAndCss(): void
{
$tagName = $this->page->locator('h1')->evaluate('element => element.tagName');
$this->assertEquals('H1', $tagName);

$width = $this->page->locator('#div-1')->evaluate('element => window.getComputedStyle(element).width');
$this->assertEquals('50px', $width);
}

private static function findFreePort(): int
{
return 0;
Expand Down