
In website management and SEO, checking for broken links (404 errors) is a critical task. However, manually opening hundreds of URLs one by one to check them is extremely time-consuming.
This article introduces a convenient GAS library that automatically crawls a list of URLs in column A of a Google Sheet and writes the result (HTTP status code) to column B.


The main purpose of this library is to automatically determine if the URLs listed in a spreadsheet are currently accessible (i.e., whether they are "live" or "dead").
It uses UrlFetchApp, a standard GAS service, to attempt to visit each URL. It then retrieves the resulting HTTP status code (e.g., 200 OK, 404 Not Found, 500 Server Error) and records it in the adjacent cell in an easy-to-understand format, such as "✅ OK (200)" or "❌ 404 Not Found".
This library is extremely helpful in the following situations:
check404Only function, you can quickly isolate only the URLs that are returning a 404 error from a massive list.This library (ID: 1mTRw0sYI7DHJ9psMiSIZ0owuExPQ3eaLAFSyu5TYnbclwp9TMBWjxwJj) is already public, so you can use it immediately by following these steps in your own Google Sheet.
1mTRw0sYI7DHJ9psMiSIZ0owuExPQ3eaLAFSyu5TYnbclwp9TMBWjxwJjClick "Look up". When the library (URLChecker) is found, click "Add".(Note: The default identifier is URLChecker, but you can change it to MyChecker or anything you like. This guide will assume you are using URLChecker.)Code.gs file, paste the following "caller code." This code acts as the switch to "run" the library's functions./**
* [Runs runCheckOnActiveSheet]
* Checks all URLs on the currently active sheet.
*/
function runCheckOnActiveSheet() {
// 1. Get the currently active sheet
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// 2. Run the library function ('URLChecker' is the identifier from step 2)
URLChecker.checkURLsInColumnA(sheet);
}
/**
* [Runs run404CheckOnActiveSheet]
* Checks URLs on the active sheet and marks 404 errors only.
*/
function run404CheckOnActiveSheet() {
// 1. Get the currently active sheet
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// 2. Run the library function
URLChecker.check404Only(sheet);
}
/**
* Automatically adds a custom menu when the
* spreadsheet is opened or reloaded.
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Custom URL Check')
.addItem('Check All URLs', 'runCheckOnActiveSheet')
.addItem('Check 404 Errors Only', 'run404CheckOnActiveSheet')
.addToUi();
}This library provides two main functions:
This function checks column A of the provided sheet row by row and records all HTTP status codes in column B.
sheet.getRange("A:A").getValues() gets all data from column A.for loop processes one URL at a time.UrlFetchApp.fetch(url, options) sends the actual HTTP request.muteHttpExceptions: true option is crucial. When true, the script will not stop if it encounters a 404 or 500 error; instead, it allows you to catch and retrieve the error status code.headers: {'User-Agent': ...} is set. Some servers block requests from the default GAS User-Agent (identifying it as a bot), so this fakes a common browser (Mozilla) User-Agent to ensure access.response.getResponseCode() retrieves the status code (200, 404, etc.).results.push(...) temporarily stores results in an array. Finally, resultRange.setValues(results) writes all results to column B at once (which is much faster than writing row by row).Utilities.sleep(200) adds a 200ms (0.2-second) pause between requests. This is an important rate-limiting measure to avoid overwhelming the target server with too many requests in a short time.The basic structure of this function is identical to checkURLsInColumnA, but the logic for writing results is different.
results.push(['❌ 404 Not Found']) if the status code is 404.results.push(['']), leaving the cell in column B blank.This allows you to quickly see only the URLs that are broken, making it easy to identify and fix the problem spots.
No, it is not. This is a third-party Google Apps Script (GAS) library (URLChecker). To use it, you must follow the setup steps in the article: open Apps Script from your spreadsheet, add the library using the Script ID, and paste the "calling code" yourself.
Yes, that is an intentional part of its design. As explained in the "Internal Code Explanation" section, the Utilities.sleep(200) function adds a 0.2-second wait after each URL request. This is a crucial "rate-limiting" measure to avoid overwhelming the server you are checking with too many requests in a short time.
Yes, that is the intended behavior. As explained in the "2. check404Only(sheet)" section, this function only writes "❌ 404 Not Found" in column B for URLs that return a 404 status. For all other URLs (like 200 OK), it is designed to write an empty string (['']) in column B. This overwrites and clears any existing "OK" messages, leaving you with a list that only flags the URLs that are currently 404 errors.
We can customize this sample to match your specific business requirements.
Book Free ConsultationPut it on Trello!Need a fix for HubSpot, CMS, or GAS? Post it on Trello.
Development Requests Here