Repository: microsoft/playwright-python
Pull request #2703 (2024-12-30 17:06:01)

build(deps): bump mypy from 1.14.0 to 1.14.1
Bumps [mypy](https://github.com/python/mypy) from 1.14.0 to 1.14.1.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/python/mypy/commit/251d12fe9f89f8d4818fd6ff1c48224e77119004"><code>251d12f</code></a> Remove +dev from version for release 1.14.1</li>
<li><a href="https://github.com/python/mypy/commit/667e5f752aaa4d1c62341d27af54e9ffff82620c"><code>667e5f7</code></a> Revert &quot;Remove redundant inheritances from Iterator in builtins&quot; (<a href="https://redirect.github.com/python/mypy/issues/18324">#18324</a>)</li>
<li><a href="https://github.com/python/mypy/commit/67f673a79d3114b3aa06d9642b9feefc2f20631a"><code>67f673a</code></a> Fix enum truthiness for StrEnum (<a href="https://redirect.github.com/python/mypy/issues/18379">#18379</a>)</li>
<li><a href="https://github.com/python/mypy/commit/3755abbb875c80698c928711b5aa8f59e71ce973"><code>3755abb</code></a> Fix getargs argument passing (<a href="https://redirect.github.com/python/mypy/issues/18350">#18350</a>)</li>
<li><a href="https://github.com/python/mypy/commit/b9fa8eeaebfda2b6ac01a2651659d3206fab9854"><code>b9fa8ee</code></a> Update version to 1.14.1+dev for point release</li>
<li>See full diff in <a href="https://github.com/python/mypy/compare/v1.14.0...v1.14.1">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=mypy&package-manager=pip&previous-version=1.14.0&new-version=1.14.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/local-requirements.txt b/local-requirements.txt
index 4f458d4..d0fc629 100644
--- a/local-requirements.txt
+++ b/local-requirements.txt
@@ -3,14 +3,14 @@ black==24.8.0
 build==1.2.2.post1
 flake8==7.1.1
 flaky==3.8.1
-mypy==1.14.0
+mypy==1.14.1
 objgraph==3.6.2
 Pillow==10.4.0
 pixelmatch==0.3.0
 pre-commit==3.5.0
 pyOpenSSL==24.3.0
 pytest==8.3.4
-pytest-asyncio==0.25.0
+pytest-asyncio==0.25.1
 pytest-cov==6.0.0
 pytest-repeat==0.9.3
 pytest-timeout==2.3.1
diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py
index f415d59..e5a9b14 100644
--- a/playwright/_impl/_browser_context.py
+++ b/playwright/_impl/_browser_context.py
@@ -692,7 +692,10 @@ class BrowserContext(ChannelOwner):
                 asyncio.create_task(dialog.dismiss())
 
     def _on_page_error(self, error: Error, page: Optional[Page]) -> None:
-        self.emit(BrowserContext.Events.WebError, WebError(self._loop, page, error))
+        self.emit(
+            BrowserContext.Events.WebError,
+            WebError(self._loop, self._dispatcher_fiber, page, error),
+        )
         if page:
             page.emit(Page.Events.PageError, error)
 
diff --git a/playwright/_impl/_web_error.py b/playwright/_impl/_web_error.py
index eb1b519..345f95b 100644
--- a/playwright/_impl/_web_error.py
+++ b/playwright/_impl/_web_error.py
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 from asyncio import AbstractEventLoop
-from typing import Optional
+from typing import Any, Optional
 
 from playwright._impl._helper import Error
 from playwright._impl._page import Page
@@ -21,9 +21,14 @@ from playwright._impl._page import Page
 
 class WebError:
     def __init__(
-        self, loop: AbstractEventLoop, page: Optional[Page], error: Error
+        self,
+        loop: AbstractEventLoop,
+        dispatcher_fiber: Any,
+        page: Optional[Page],
+        error: Error,
     ) -> None:
         self._loop = loop
+        self._dispatcher_fiber = dispatcher_fiber
         self._page = page
         self._error = error
 
diff --git a/playwright/async_api/__init__.py b/playwright/async_api/__init__.py
index a64a066..be918f5 100644
--- a/playwright/async_api/__init__.py
+++ b/playwright/async_api/__init__.py
@@ -60,6 +60,7 @@ from playwright.async_api._generated import (
     Selectors,
     Touchscreen,
     Video,
+    WebError,
     WebSocket,
     WebSocketRoute,
     Worker,
@@ -190,6 +191,7 @@ __all__ = [
     "Touchscreen",
     "Video",
     "ViewportSize",
+    "WebError",
     "WebSocket",
     "WebSocketRoute",
     "Worker",
diff --git a/playwright/sync_api/__init__.py b/playwright/sync_api/__init__.py
index 80eaf71..1364339 100644
--- a/playwright/sync_api/__init__.py
+++ b/playwright/sync_api/__init__.py
@@ -60,6 +60,7 @@ from playwright.sync_api._generated import (
     Selectors,
     Touchscreen,
     Video,
+    WebError,
     WebSocket,
     WebSocketRoute,
     Worker,
@@ -190,6 +191,7 @@ __all__ = [
     "Touchscreen",
     "Video",
     "ViewportSize",
+    "WebError",
     "WebSocket",
     "WebSocketRoute",
     "Worker",


Test patch:
diff --git a/tests/async/test_browsercontext_events.py b/tests/async/test_browsercontext_events.py
index a0a3b90..8ae14de 100644
--- a/tests/async/test_browsercontext_events.py
+++ b/tests/async/test_browsercontext_events.py
@@ -17,7 +17,7 @@ from typing import Optional
 
 import pytest
 
-from playwright.async_api import Page
+from playwright.async_api import BrowserContext, Page
 from tests.utils import must
 
 from ..server import Server, TestServerRequest
@@ -198,3 +198,11 @@ async def test_page_error_event_should_work(page: Page) -> None:
     page_error = await page_error_info.value
     assert page_error.page == page
     assert "boom" in page_error.error.stack
+
+
+async def test_weberror_event_should_work(context: BrowserContext, page: Page) -> None:
+    async with context.expect_event("weberror") as error_info:
+        await page.goto('data:text/html,<script>throw new Error("Test")</script>')
+    error = await error_info.value
+    assert error.page == page
+    assert error.error.message == "Test"
diff --git a/tests/sync/test_browsercontext_events.py b/tests/sync/test_browsercontext_events.py
index 315fff0..6e44b76 100644
--- a/tests/sync/test_browsercontext_events.py
+++ b/tests/sync/test_browsercontext_events.py
@@ -16,7 +16,7 @@ from typing import Optional
 
 import pytest
 
-from playwright.sync_api import Dialog, Page
+from playwright.sync_api import BrowserContext, Dialog, Page
 
 from ..server import Server, TestServerRequest
 
@@ -198,3 +198,11 @@ def test_console_event_should_work_with_context_manager(page: Page) -> None:
     message = cm_info.value
     assert message.text == "hello"
     assert message.page == page
+
+
+def test_weberror_event_should_work(context: BrowserContext, page: Page) -> None:
+    with context.expect_event("weberror") as error_info:
+        page.goto('data:text/html,<script>throw new Error("Test")</script>')
+    error = error_info.value
+    assert error.page == page
+    assert error.error.message == "Test"