Skip to content
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

[🐛 Bug]: #14777

Open
morettolss opened this issue Nov 19, 2024 · 2 comments
Open

[🐛 Bug]: #14777

morettolss opened this issue Nov 19, 2024 · 2 comments

Comments

@morettolss
Copy link

What happened?

I had a particular case, creating the file and calling the function at the same time it happened that the first file was overwritten by the second one that was being generated. The error does not seem to be reproducible in a standard way but only after X attempts.

How can we reproduce the issue?

print_settings = {
            "recentDestinations": [{
                "id": "Save as PDF",
                "origin": "local",
                "account": "",
            }],
            "selectedDestinationId": "Save as PDF",
            "version": 2,
            "isHeaderFooterEnabled": False,
            "isLandscapeEnabled": True
        }

        user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_2) AppleWebKit/537.36 (KHTML, like Gecko) ' \
                    'Chrome/110.0.0.0 Safari/537.36'

        options = webdriver.ChromeOptions()
        options.add_argument(f'user-agent={user_agent}')
        options.add_argument("--start-maximized")
        options.add_argument('--window-size=1920,1080')
        options.add_argument(f"user-data-dir=path/tmp/")
        options.add_argument("--headless")
        options.add_argument('--disable-gpu')
        options.add_argument('--no-sandbox')
        options.add_argument('--enable-print-browser')
        options.add_experimental_option("prefs", {
            "printing.print_preview_sticky_settings.appState": json.dumps(print_settings),
            "savefile.default_directory": f'path/tmp/',  # Change default directory for downloads
            "download.default_directory": f'path/tmp/',  # Change default directory for downloads
            "download.prompt_for_download": False,  # To auto download the file
            "download.directory_upgrade": True,
            "profile.default_content_setting_values.automatic_downloads": 1,
            "safebrowsing.enabled": True
        })
        options.add_argument("--kiosk-printing")

        #driver = Chrome(service=service, options=options)
        driver = Chrome( options=options)
        html_bs64 = base64.b64encode(body.encode('utf-8')).decode()
        driver.get("data:text/html;base64," + html_bs64)
        pdf_data = driver.execute_cdp_cmd("Page.printToPDF", print_settings)
        driver.quit()
        f = open(fname_dir, 'wb')
        f.write(base64.b64decode(pdf_data['data']))
        f.close()

Relevant log output

no log output

Operating System

ubuntu

Selenium version

pytohn selenium==4.24.0

What are the browser(s) and version(s) where you see this issue?

Chrome 110

What are the browser driver(s) and version(s) where you see this issue?

Chrome 110

Are you using Selenium Grid?

No response

Copy link

@morettolss, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@morettolss
Copy link
Author

morettolss commented Nov 19, 2024

to replicate the problem it's possible to add a time.sleep(1) after the pdf_data

        driver = Chrome( options=options)
        html_bs64 = base64.b64encode(body.encode('utf-8')).decode()
        driver.get("data:text/html;base64," + html_bs64)
        pdf_data = driver.execute_cdp_cmd("Page.printToPDF", print_settings)
        time.sleep(1)
        driver.quit()
        #print(pdf_data['data'])
        f = open(fname_dir, 'wb')
        f.write(base64.b64decode(pdf_data['data']))
        f.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant