Skip to content

docs: close included page on failure in scrolling example - #404

Open
the-nguyener wants to merge 1 commit into
scrapy-plugins:mainfrom
the-nguyener:docs-scroll-example-cleanup
Open

the-nguyener wants to merge 1 commit into
scrapy-plugins:mainfrom
the-nguyener:docs-scroll-example-cleanup

Conversation

@the-nguyener

Copy link
Copy Markdown

The scrolling example in docs/examples.rst sets playwright_include_page=True but has no errback. If request processing fails, like when wait_for_selector times out, the page is left open during the crawl. The handler skips closing included pages on error, and docs/pages.rst recommends an errback for this case. Unclosed pages count against the page limit and can stall later requests.

This adds a closing errback following the pattern in docs/pages.rst. It also wraps the screenshot in try/finally so the page closes if the screenshot raises.

Validation used static localhost HTML, the real handler, and Chromium with Python 3.12, Scrapy 2.20, and Playwright 1.57. Before the change, request timeout and screenshot failure each left one page open and blocked a follow-up request. After the change, both failure cases and the success control left zero open pages, and all follow-up requests returned HTTP 200 without manual cleanup. The harness drove the handler directly rather than running a full Scrapy crawl.

The docs build, Flake8, and Black pass.

@AdrianAtZyte

Copy link
Copy Markdown
Contributor

Aren’t examples simpler than real code on purpose?

@the-nguyener

Copy link
Copy Markdown
Author

Fair point, examples should stay simple. My concern was that this one sets playwright_include_page=True, which makes the page the user's responsibility, and the page closing section of the docs recommends an errback for that. So copying the example leaves a page open if the request times out. I can trim it to just the errback, or I can take the screenshot with a PageMethod instead, so no page handling is needed. Which would you prefer?

@AdrianAtZyte

Copy link
Copy Markdown
Contributor

The PageMethod one, please, like in examples/scroll.py.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants