New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to turn off log errors generated by interception #1185
Comments
Could you provide us a full example of your code? I tried the following which was working fine for me: import asyncio
from playwright.async_api import async_playwright
async def no_static(route, req):
if req.resource_type in {"image", "media", "font"}:
try:
await route.fulfill(status=404, content_type="text/plain", body="not found!")
except:
pass
else:
await route.continue_()
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.route("**/*", no_static)
await page.goto('http://microsoft.com/')
await page.screenshot(path=f'example.png')
await browser.close()
asyncio.run(main()) Make sure that you only call a single time fulfill/continue/abort. Otherwise "Route is already handled! gets thrown. |
I also encountered this problem, calling function import asyncio
from playwright.async_api import async_playwright
async def no_static(route, req):
if req.resource_type in {"image", "media", "font"}:
try:
await route.fulfill(status=404, content_type="text/plain", body="not found!")
except:
pass
else:
await route.continue_()
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
context = await browser.new_context()
await context.route('**/*', no_static)
page = await context.new_page()
await page.goto('http://microsoft.com/')
await browser.close()
asyncio.run(main()) My environment: Windows10, Python 3.8.8, Playwright 1.21.0 |
Well, I've had this problem too, because I worry applying page.on(event) every single time I open a website might slow down things, even with Cython, so my solution was to check the source code. In playwright / _impl / _connection The exceptions no longer print anything, so in my opinion it was worth it. |
In the route handler its not supported to pass coroutines, the functions need to be sync. When modifying your repro @jw-star and removing the async and await, then it works as expected. |
I've tried synchronous code above before my last comment, and the error reporting is the same as asynchronous. |
I have this problem too, this error occurs when using context.route() |
Modify this file : ~Lib\site-packages\playwright\driver\package\lib\server\network.js if(!this._handled){
this._startHandling();
} I don't know if this is the right thing to do, but it does not report any error! |
@mxschmitt Hello, how about re-open this issue? |
v1.23 introduced async route handlers. There is one known, pending issue regarding errant logs, so please follow: #1402 |
The text was updated successfully, but these errors were encountered: