pythonselenium-webdriverwebgl

WebGL is disabled error when opening bing maps with python selenium?


i try to open bing maps using python selenium with this code:

import os, sys
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

options = Options()
options.add_argument("start-maximized")  
options.add_argument('--use-gl=swiftshader')
options.add_argument('--enable-unsafe-webgpu')
options.add_argument('--enable-unsafe-swiftshader')
options.add_argument("--disable-3d-apis")
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("start-maximized")
options.add_argument('--log-level=3')  
options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 1})    
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled') 
srv=Service()

baseLink = "https://www.bing.com/maps"
driver = webdriver.Chrome (service=srv, options=options)    
driver.get (baseLink)
input("Press!")

Worked fine for a long time but suddenly i get this error:

enter image description here

How can i open bing maps using python and selenium?


Solution

  • Without this option the code works:

    options.add_argument("--disable-accelerated-2d-canvas")
    

    You could try to replace it with:

    options.add_argument("--disable-accelerated-2d-canvas")
    

    Prevents fallback to software rendering when GPU is disabled—useful in combination with --disable-gpu.

    Also you may consider to add this options:

    # Disable pop-ups
    options.add_argument("--disable-popup-blocking")
    
    # Disable ads (not guaranteed, but can help)
    options.add_argument("--disable-ads")
    
    # Disable notifications
    options.add_argument("--disable-notifications")
    
    # Disable extensions (some ads come from extensions)
    options.add_argument("--disable-extensions")
    

    Moreover here is the code to click "Reject" by id:
    enter image description here

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    def click_by_id(id = "bnp_btn_reject", timeout = 10):
        try:
            WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, id))).click()
        except Exception as e:
            print(f"Error clicking button: {e}")
    click_by_id()