-
Notifications
You must be signed in to change notification settings - Fork 694
fix(playwright): filter unsupported context options in persistent browser #1796
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import inspect | ||
| import shutil | ||
| import tempfile | ||
| from logging import getLogger | ||
|
|
@@ -67,8 +68,21 @@ async def new_context(self, **context_options: Any) -> BrowserContext: | |
| user_data_dir = tempfile.mkdtemp(prefix=self._TMP_DIR_PREFIX) | ||
| self._temp_dir = Path(user_data_dir) | ||
|
|
||
| launch_persistent_context_sig = inspect.signature(self._browser_type.launch_persistent_context) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a reasonable approach, but it has some drawbacks. If user has just typo ( in otherwise valid argument name), it will just show warning in log. Same for using some completely nonsensical argument. That should raise an error and not just log a warning. For example, this should raise (typo in headles): Maybe this approach could be adopted one lever higher (not in It should properly raise exceptions for bad arguments, but it could just log a warning as per your suggestion for arguments at least valid in the other method. It would have to get 3 sets of arguments to be able to do such a distinction. Something like: And then raise an exception or just log based on the selected mode. |
||
| filtered_launch_options = { | ||
| key: value for key, value in launch_options.items() if key in launch_persistent_context_sig.parameters | ||
| } | ||
|
|
||
| removed_options = set(launch_options.keys()) - set(filtered_launch_options.keys()) | ||
| if removed_options: | ||
| logger.warning( | ||
| f"The following options are not supported by Playwright's launch_persistent_context " | ||
| f'and will be ignored: {removed_options}. ' | ||
| 'To use these options, consider using incognito pages (use_incognito_pages=True).' | ||
| ) | ||
|
|
||
| self._context = await self._browser_type.launch_persistent_context( | ||
| user_data_dir=user_data_dir, **launch_options | ||
| user_data_dir=user_data_dir, **filtered_launch_options | ||
| ) | ||
|
|
||
| if self._temp_dir: | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have all these added dependencies in the optional dependencies group playwright. So please remove them from here.