mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.03k stars 1.51k forks source link

Bug: When screenshotting a very long element, text at the bottom of the image is saved with a black background #2133

Open void4 opened 9 months ago

void4 commented 9 months ago

System

Problem

When taking a screenshot of a very long (vertically large) element on a page (e.g. https://icebergcharts.com/i/The_Complete_Geometry_Dash?watermark=true), text at the bottom of the page gets a black background in the image that isn't there on the original page. Note that in this case this only affects four "rows" at the very bottom of the page.

Testcase

from time import sleep

from selenium import webdriver

def snap(url, target):

    geckopath = "/home/test/geckodriver"

    opt = webdriver.FirefoxOptions()
    opt.add_argument('-headless')
    opt.add_argument("--width=1920")
    opt.add_argument("--height=1080")

    if DEBUG:
        print("starting webdriver")

    driver = webdriver.Firefox(executable_path=geckopath, options=opt)
    try:
        print("getting url")
        driver.get(url)

        print("sleeping")
        sleep(3)

        print("taking screenshot")
        element = driver.find_element_by_id("iceberg")
        element_png = element.screenshot_as_png
        with open(target, "wb") as file:
            file.write(element_png)

    finally:
        driver.quit()

snap("https://icebergcharts.com/i/The_Complete_Geometry_Dash?watermark=true", "snapshot.png")
whimboo commented 9 months ago

For me only the very last line, which is the footer, is not getting a background. Is that what you mean? I do not see 4 rows. Does the screenshot work when you only screenshot this particular element? If you could test that I would appreciate. Thanks!

void4 commented 9 months ago

Ah, sorry, should have been more specific, I mean this: image

The black rectangles behind the text are not there on the page

whimboo commented 9 months ago

I can see that now as well. The internal print as PDF feature of Firefox doesn't seem to produce that. Interesting is that we basically use the exact same API for it. Would you mind to maybe reduce this very huge test case? It would be much easier to investigate or point to a specific known bug when the HTML / CSS would be minimized.

void4 commented 9 months ago

I can, but give me a few days. There seem to be more text-related problems when it comes to long pages, such as incompletely rendered text (see the "Exen is legi?" entry on the left), and also text not appearing at all on very long pages.

I can't tell if this is a problem with the Geckodriver, or maybe just due to rendering taking so long for the browser, and me waiting not long enough to take a screenshot (?), or maybe something related to the full view not being always rendered for efficiency, which then causes elements to be missing in the screenshot.

whimboo commented 9 months ago

Sure no worries. It most likely wont be a priority right now for geckodriver, but in case its a bug in Gecko itself we could more easily find a solution then. Thanks!

whimboo commented 8 months ago

@void4 I wanted to check back if you had a chance to find / create a minimized testcase for this scenario. If not we may have to work with the full page to figure out what's wrong. Thanks.

void4 commented 8 months ago

No, not yet - I'm currently focusing on other things, so this isn't a priority for me, though it would be nice to see a solution