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

uncorrect working page.screenshot, page.set_viewport_size, page.evaluate #132

Open
Pyunstoppable opened this issue Dec 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Pyunstoppable
Copy link

Describe the bug:

await page.screenshot(full_page=True) does not work correctly in playwright, but this is solved by a workaround - you need to set viewport_size to the page height and execute page.screenshot(full_page=False), you will get a screenshot of the whole page, and it will be correct, but it doesn't work in Camoufox (look at "accept cookies").

Screenshots:

look at "accept cookies"

Camoufox:

screenshot_0_0_full

Playwright:

screenshot_0_0_full_pw

To Reproduce:

# "https://www.unimelb.edu.au/"

total_height = await page.evaluate("document.body.scrollHeight")
	
width = page.viewport_size['width']
height = page.viewport_size['height']

await page.set_viewport_size({"width": width, "height": total_height})

# await page.screenshot(full_page=True, path=full_screenshot_path, type='jpeg')

await page.screenshot(full_page=False, path=full_screenshot_path, type='jpeg')

# restore viewport_size
await page.set_viewport_size({"width": width, "height": height})

next bug

if you add scrolling to the code

await page.evaluate(f"window.scrollTo(0, {scroll_amount})")

then on the second iteration of the loop we move not from the beginning of the page, but from the previous offset.

screenshot_1_0_full

Version:

Pip package: v0.4.8
Camoufox: v133.0-beta.19 (Up to date!)

@Pyunstoppable Pyunstoppable added the bug Something isn't working label Dec 12, 2024
@D4Vinci
Copy link
Contributor

D4Vinci commented Jan 7, 2025

Why won't you just click accept cookies if it's presented?

That's what I normally do in automation tasks

import asyncio
from camoufox.async_api import AsyncCamoufox
async def main():
    async with AsyncCamoufox(headless=False, humanize=False, window=(1280, 720)) as browser:
        page = await browser.new_page()
        page.set_default_navigation_timeout(30000)
        page.set_default_timeout(30000)
        await page.goto('https://www.unimelb.edu.au/')
        await page.wait_for_load_state(state="domcontentloaded")
        if 'consent_prompt_submit' in await page.content():
            await page.locator('#consent_prompt_submit').first.click()
        await page.screenshot(full_page=True, path='test.jpeg', type='jpeg')
        await browser.close()

if __name__ == "__main__":
    asyncio.run(main())

The result is this:

test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants