Skip to content

Commit c9cd855

Browse files
authored
Merge pull request #14 from andywer/feature/make-web-workers-work
Make web workers work
2 parents affb308 + 4245741 commit c9cd855

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

src/cli.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import serveBundle from "./bundle"
88
import { copyFiles } from "./fs"
99
import { isPluginArgument, loadPlugin, printPluginHelp } from "./plugins"
1010
import { spawnPuppet } from "./puppeteer"
11-
import { clearTemporaryFileCache, createTemporaryFileCache } from "./temporary"
11+
import { clearTemporaryFileCache, createTemporaryFileCache, writeBlankHtmlPage } from "./temporary"
1212

1313
const cli = meow(`
1414
Usage
@@ -18,7 +18,6 @@ const cli = meow(`
1818
Options
1919
--help Show this help.
2020
--inspect Run in actual Chrome window and keep it open.
21-
--secure-origin Give the Chrome page a secure origin
2221
--p <port>, --port <port> Serve on this port. Defaults to random port.
2322
--serve <./file>[:</serve/here>] Serve additional files next to bundle.
2423
@@ -65,7 +64,6 @@ async function run () {
6564
const entrypoint = process.argv[firstArgumentIndex]
6665

6766
const headless = runnerOptionArgs.indexOf("--inspect") > -1 ? false : true
68-
const secureOrigin = runnerOptionArgs.indexOf("--secure-origin") > -1
6967
const port = runnerOptions.p || runnerOptions.port
7068
? parseInt(runnerOptions.p || runnerOptions.port, 10)
7169
: await getPort()
@@ -83,10 +81,11 @@ async function run () {
8381

8482
try {
8583
const serverURL = `http://localhost:${port}/`
84+
writeBlankHtmlPage(path.join(temporaryCache, "index.html"))
8685

8786
const { bundle, server } = await serveBundle(scriptPaths, temporaryCache, port)
8887
await copyFiles(additionalFilesToServe, temporaryCache)
89-
const puppet = await spawnPuppet(bundle, serverURL, { headless, secureOrigin })
88+
const puppet = await spawnPuppet(bundle, serverURL, { headless })
9089
await puppet.run(scriptArgs, plugin)
9190

9291
exitCode = await puppet.waitForExit()

src/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function copyFile (from: string, to: string) {
1717
})
1818
}
1919

20-
export async function copyFiles (filesToServe: Array<FileToServe>, destinationDirectory: string) {
20+
export async function copyFiles (filesToServe: FileToServe[], destinationDirectory: string) {
2121
return Promise.all(filesToServe.map(
2222
async ({ servingPath, sourcePath }) => {
2323
const destinationFilePath = path.resolve(destinationDirectory, servingPath.replace(/^\//, ""))

src/puppeteer.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ function createExitPromise (page: Page) {
109109
})
110110
}
111111

112-
export async function spawnPuppet(bundle: ParcelBundle, serverURL: string, options: { headless?: boolean, secureOrigin?: boolean }): Promise<Puppet> {
112+
export async function spawnPuppet(bundle: ParcelBundle, serverURL: string, options: { headless?: boolean }): Promise<Puppet> {
113+
let puppetExit: Promise<number>
113114
const { headless = true } = options
114115

115116
const browser = await launch({
@@ -119,12 +120,8 @@ export async function spawnPuppet(bundle: ParcelBundle, serverURL: string, optio
119120

120121
const [ page ] = await browser.pages()
121122

122-
if (options.secureOrigin) {
123-
// https://github.com/GoogleChrome/puppeteer/issues/2301
124-
await page.goto("file:///")
125-
}
126-
127-
let puppetExit: Promise<number>
123+
// Navigate to a secure origin first. See <https://github.com/GoogleChrome/puppeteer/issues/2301>
124+
await page.goto(serverURL + "index.html")
128125

129126
capturePuppetConsole(page)
130127

src/script-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ interface ScriptError extends Error { }
33

44
// tslint:disable-next-line:no-shadowed-variable
55
const ScriptError = function ScriptError(this: ScriptError, error: Error, stack?: string) {
6-
Error.call(this, <any>error)
6+
Error.call(this, error as any)
77
Object.defineProperty(this, "message", {
88
enumerable: false,
99
value: error.message

src/temporary.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ export function createTemporaryFileCache (): TemporaryFileCache {
1212
export function clearTemporaryFileCache (cache: TemporaryFileCache) {
1313
rimraf.sync(cache)
1414
}
15+
16+
export function writeBlankHtmlPage (filePath: string) {
17+
const content = `
18+
<!doctype html>
19+
<html>
20+
<head></head>
21+
<body><!-- Blank page as a launch pad to inject JS scripts into --></body>
22+
</html>
23+
`.trim()
24+
fs.writeFileSync(filePath, content, "utf8")
25+
}

0 commit comments

Comments
 (0)