Home / Companies / Checkly / Blog / Post Details
Content Deep Dive

How to detect broken links with Playwright

Blog post from Checkly

Post Details
Company
Date Published
Author
Stefan Judis
Word Count
1,879
Language
English
Hacker News Points
-
Summary

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.