-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from marp-team/browser-manager
Allow using Firefox / WebDriver BiDi protocol during conversion
- Loading branch information
Showing
43 changed files
with
1,936 additions
and
1,375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* For baking the ICU data into the standalone binary, we need to download the compatible ICU data from the ICU repository. */ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { promisify } from 'node:util' | ||
import yauzl from 'yauzl' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
const icuDir = path.join(__dirname, '../tmp/icu') | ||
await fs.promises.mkdir(icuDir, { recursive: true }) | ||
|
||
const zipFromBuffer = promisify(yauzl.fromBuffer) | ||
|
||
// Get the ICU version and endianness | ||
const [icuMajor, icuMinor] = process.versions.icu.split('.') | ||
const icuEndianness = process.config.variables.icu_endianness.toLowerCase() | ||
|
||
// Download the ICU data | ||
const response = await fetch( | ||
`https://github.com/unicode-org/icu/releases/download/release-${icuMajor}-${icuMinor}/icu4c-${icuMajor}_${icuMinor}-data-bin-${icuEndianness}.zip` | ||
) | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to download ICU data: ${response.statusText}`) | ||
} | ||
|
||
// Extract the ICU data | ||
const zip = await zipFromBuffer(Buffer.from(await response.arrayBuffer()), { | ||
lazyEntries: true, | ||
}) | ||
|
||
const icuDat = await new Promise((res, rej) => { | ||
zip.on('error', (err) => rej(err)) | ||
zip.on('entry', async (entry) => { | ||
if (/icudt\d+.\.dat/.test(entry.fileName)) { | ||
zip.openReadStream(entry, (err, readStream) => { | ||
if (err) return rej(err) | ||
|
||
const output = path.join(icuDir, entry.fileName) | ||
|
||
readStream.pipe(fs.createWriteStream(output)) | ||
res(output) | ||
}) | ||
} else { | ||
zip.readEntry() | ||
} | ||
}) | ||
zip.on('end', () => rej(new Error('Failed to find ICU data in the archive'))) | ||
zip.readEntry() | ||
}) | ||
|
||
// Print the relative path to the ICU data from the project root | ||
console.log(path.relative(path.join(__dirname, '../'), icuDat)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
import { Browser } from '../browser' | ||
import type { PuppeteerLaunchOptions } from 'puppeteer-core' | ||
import macDockIcon from '../../assets/mac-dock-icon.png' | ||
import { BrowserProtocol } from '../browser' | ||
import { ChromeBrowser } from './chrome' | ||
|
||
export class ChromeCdpBrowser extends Browser { | ||
static readonly kind = 'chrome' as const | ||
static readonly protocol = 'cdp' as const | ||
export class ChromeCdpBrowser extends ChromeBrowser { | ||
static readonly protocol: BrowserProtocol = 'cdp' | ||
|
||
protected async launchPuppeteer(opts: PuppeteerLaunchOptions) { | ||
const puppeteer = await super.launchPuppeteer(opts) | ||
|
||
// macOS specific: Set Marp icon asynchrnously | ||
if (process.platform === 'darwin') { | ||
puppeteer | ||
.target() | ||
.createCDPSession() | ||
.then((session) => { | ||
session | ||
.send('Browser.setDockTile', { image: macDockIcon.slice(22) }) | ||
.catch(() => void 0) | ||
}) | ||
} | ||
|
||
return puppeteer | ||
} | ||
} |
Oops, something went wrong.