Skip to content

Commit d51bb02

Browse files
🔧 Disable notifications (#73)
* 🔧 Disable notifications * exclude webkit * firefox_user_prefs
1 parent 5faac9b commit d51bb02

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

dude/optional/pyppeteer_scraper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def _run_async(
106106
output: Optional[str],
107107
format: str,
108108
) -> None:
109-
launch_args: Dict[str, Any] = {"headless": headless, "args": ["--no-sandbox"]}
109+
launch_args: Dict[str, Any] = {"headless": headless, "args": ["--no-sandbox", "--disable-notifications"]}
110110
if proxy:
111111
launch_args["args"] = [f"--proxy-server={proxy['server']}"]
112112

dude/optional/selenium_scraper.py

+2
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,12 @@ def _get_driver(browser_type: str, headless: bool) -> WebDriver:
210210
executable_path = GeckoDriverManager().install()
211211
firefox_options = FirefoxOptions()
212212
firefox_options.headless = headless
213+
firefox_options.set_preference("dom.webnotifications.enabled", False)
213214
return webdriver.Firefox(service=FirefoxService(executable_path=executable_path), options=firefox_options)
214215

215216
chrome_options = ChromeOptions()
216217
chrome_options.headless = headless
218+
chrome_options.add_argument("disable-notifications")
217219
executable_path = ChromeDriverManager(
218220
chrome_type=ChromeType.CHROMIUM, version=os.getenv("CHROMEDRIVER_VERSION", "latest")
219221
).install()

dude/playwright_scraper.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ def _run_sync(
153153
) -> None:
154154
# FIXME: Coverage fails to cover anything within this context manager block
155155
with sync_playwright() as p:
156-
browser = p[browser_type].launch(headless=headless, proxy=proxy)
156+
args = []
157+
if browser_type == "chromium":
158+
args.append("--disable-notifications")
159+
browser = p[browser_type].launch(
160+
headless=headless, proxy=proxy, args=args, firefox_user_prefs={"dom.webnotifications.enabled": False}
161+
)
157162
page = browser.new_page()
158163
self._scrape_sync(page, urls, pages)
159164
browser.close()
@@ -182,7 +187,12 @@ async def _run_async(
182187
format: str,
183188
) -> None:
184189
async with async_playwright() as p:
185-
browser = await p[browser_type].launch(headless=headless, proxy=proxy)
190+
args = []
191+
if browser_type == "chromium":
192+
args.append("--disable-notifications")
193+
browser = await p[browser_type].launch(
194+
headless=headless, proxy=proxy, args=args, firefox_user_prefs={"dom.webnotifications.enabled": False}
195+
)
186196
page = await browser.new_page()
187197
for url in urls:
188198
await page.goto(url)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pydude"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
repository = "https://github.com/roniemartinez/dude"
55
description = "dude uncomplicated data extraction"
66
authors = ["Ronie Martinez <ronmarti18@gmail.com>"]

0 commit comments

Comments
 (0)