/plushcap/analysis/checkly/checkly-how-to-detect-broken-links-with-playwright

How to detect broken links with Playwright

What's this blog post about?

To detect broken links on a website using Playwright and Checkly, one can extract all link URLs from a page, make requests to these URLs, and evaluate their status code. The process involves several steps, including extracting the `href` attribute value from all links, saving requests and removing duplicate link targets, normalizing local link targets to absolute URLs, and checking for broken link URLs. This can be done using Playwright's lazy locator behavior, native JavaScript features such as sets and URL constructors, and soft assertions to collect errors without stopping the test case. The final implementation can be found on GitHub, allowing users to run Playwright in their CICD pipeline and check for broken links whenever they deploy their sites.

Company
Checkly

Date published
Sept. 6, 2024

Author(s)
Stefan Judis

Word count
1879

Language
English

Hacker News points
None found.


By Matt Makai. 2021-2024.