New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

playwright-deblock

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

playwright-deblock

Automatic fix for Playwright file:// navigation blocks. One require(), works forever.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

playwright-deblock

Automatic fix for Playwright file:// navigation blocks. One require(), works forever.

Problem

Restricted Playwright runners block file:// URLs:

Access to 'file:' URL is blocked. Allowed protocols: http, https, about, data.

Solution

npm install playwright-deblock
require("playwright-deblock");

Done. Every page.goto("file://...") is now automatically served over http://localhost.

Usage

// Add this ONE line at the top of your script or test
require("playwright-deblock");

// Then use file:// like normal — it just works
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto("file:///home/user/page.html"); // auto-redirected to http://

Playwright config (global)

// playwright.config.js
module.exports = {
  globalSetup: require.resolve("playwright-deblock/register"),
};

Or via CLI:

npx playwright test --require playwright-deblock/register

With options

const deblock = require("playwright-deblock");
deblock.apply({ strategy: "data", silent: true });

Manual helper (no monkey-patching)

const { serveAndGoto, cleanup } = require("playwright-deblock/helper");

test("loads local HTML", async ({ page }) => {
  await serveAndGoto(page, "/path/to/file.html");
  await expect(page.locator("h1")).toBeVisible();
});

test.afterAll(() => cleanup());

How it works

StrategyProtocolMethod
http (primary)http://Starts localhost server, serves the file's directory
data (fallback)data:Inlines CSS/JS/images into a data: URL
  • Original HTML files are never modified on disk
  • One server per directory, reused across calls
  • Servers auto-cleanup on process exit
  • Works with chromium, firefox, webkit
  • Works with playwright and playwright-core

API

ExportDescription
apply(opts?)Re-apply patch with options
cleanup()Stop all HTTP servers
convertUrl(url)Convert a file:// URL manually
serveAndGoto(page, path)Navigate without monkey-patching
buildDataUrl(path)Build a data: URL from HTML file
inlineAssets(path)Inline assets into HTML string

License

MIT

Keywords

playwright

FAQs

Package last updated on 20 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts