2022-07-01 11:52:39 +00:00
|
|
|
/**
|
2024-01-03 10:11:33 +00:00
|
|
|
* @license
|
|
|
|
* Copyright 2022 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2022-07-01 11:52:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
// Note: type annotations allow type checking and IDEs autocompletion
|
|
|
|
|
2023-02-15 23:09:31 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
|
2023-11-29 12:06:05 +00:00
|
|
|
const {themes} = require('prism-react-renderer');
|
|
|
|
const darkCodeTheme = themes.dracula;
|
|
|
|
const lightCodeTheme = themes.github;
|
2023-10-12 13:04:29 +00:00
|
|
|
const semver = require('semver');
|
2022-07-01 11:52:39 +00:00
|
|
|
|
2022-08-09 11:13:05 +00:00
|
|
|
const archivedVersions = require('./versionsArchived.json');
|
|
|
|
|
2022-07-01 11:52:39 +00:00
|
|
|
const DOC_ROUTE_BASE_PATH = '/';
|
|
|
|
const DOC_PATH = '../docs';
|
|
|
|
|
2023-10-12 13:04:29 +00:00
|
|
|
/**
|
|
|
|
* This logic should match the one in `Herebyfile.mjs`.
|
|
|
|
*/
|
|
|
|
function getApiUrl(version) {
|
|
|
|
if (semver.gte(version, '19.3.0')) {
|
|
|
|
return `https://github.com/puppeteer/puppeteer/blob/puppeteer-${version}/docs/api/index.md`;
|
|
|
|
} else if (semver.gte(version, '15.3.0')) {
|
|
|
|
return `https://github.com/puppeteer/puppeteer/blob/${version}/docs/api/index.md`;
|
|
|
|
} else {
|
|
|
|
return `https://github.com/puppeteer/puppeteer/blob/${version}/docs/api.md`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 11:52:39 +00:00
|
|
|
/** @type {import('@docusaurus/types').Config} */
|
|
|
|
const config = {
|
|
|
|
title: 'Puppeteer',
|
|
|
|
tagline: 'Headless Chrome Node.js API',
|
|
|
|
url: 'https://pptr.dev',
|
|
|
|
baseUrl: '/',
|
|
|
|
onBrokenLinks: 'warn',
|
|
|
|
onBrokenMarkdownLinks: 'warn',
|
|
|
|
favicon: 'img/favicon.ico',
|
|
|
|
organizationName: 'puppeteer',
|
|
|
|
projectName: 'puppeteer',
|
|
|
|
i18n: {
|
|
|
|
defaultLocale: 'en',
|
|
|
|
locales: ['en'],
|
|
|
|
},
|
2023-01-11 14:51:39 +00:00
|
|
|
scripts: [
|
|
|
|
{
|
|
|
|
src: '/fix-location.js',
|
|
|
|
async: false,
|
|
|
|
defer: false,
|
|
|
|
},
|
|
|
|
],
|
2022-09-12 11:59:05 +00:00
|
|
|
webpack: {
|
|
|
|
jsLoader: isServer => {
|
|
|
|
return {
|
|
|
|
loader: require.resolve('swc-loader'),
|
|
|
|
options: {
|
|
|
|
jsc: {
|
|
|
|
parser: {
|
|
|
|
syntax: 'typescript',
|
|
|
|
tsx: true,
|
|
|
|
},
|
|
|
|
target: 'es2017',
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
type: isServer ? 'commonjs' : 'es6',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2022-10-28 06:49:28 +00:00
|
|
|
plugins: [
|
|
|
|
[
|
|
|
|
'client-redirects',
|
|
|
|
/** @type {import('@docusaurus/plugin-client-redirects').Options} */
|
|
|
|
({
|
|
|
|
redirects: [
|
|
|
|
{
|
|
|
|
from: '/guides',
|
|
|
|
to: '/category/guides',
|
|
|
|
},
|
2024-04-08 09:14:55 +00:00
|
|
|
{
|
|
|
|
from: '/chromium-support',
|
|
|
|
to: '/supported-browsers',
|
|
|
|
},
|
2022-10-28 06:49:28 +00:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
],
|
2022-07-01 11:52:39 +00:00
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'classic',
|
|
|
|
/** @type {import('@docusaurus/preset-classic').Options} */
|
|
|
|
({
|
|
|
|
pages: false,
|
|
|
|
blog: false,
|
|
|
|
docs: {
|
|
|
|
async sidebarItemsGenerator({defaultSidebarItemsGenerator, ...args}) {
|
|
|
|
const sidebarItems = await defaultSidebarItemsGenerator(args);
|
2022-10-28 06:49:28 +00:00
|
|
|
|
|
|
|
/** @type {typeof sidebarItems} */
|
|
|
|
const apiSidebarItems = [];
|
|
|
|
const categories = new Map();
|
|
|
|
for (const item of sidebarItems) {
|
|
|
|
assert(item.type === 'doc' && item.label);
|
|
|
|
const [namespace] = item.label.split('.');
|
|
|
|
if (!categories.has(namespace)) {
|
|
|
|
categories.set(namespace, [item]);
|
|
|
|
} else {
|
|
|
|
categories.get(namespace).push(item);
|
2022-09-12 11:00:37 +00:00
|
|
|
}
|
2022-10-28 06:49:28 +00:00
|
|
|
}
|
2022-09-12 11:00:37 +00:00
|
|
|
|
2022-10-28 06:49:28 +00:00
|
|
|
function addNamespace(namespace, target) {
|
|
|
|
let items = categories.get(namespace);
|
|
|
|
if (!items) {
|
2023-05-02 07:48:18 +00:00
|
|
|
throw new Error(
|
|
|
|
`Namespace ${namespace} not found. Did you update the list of sidebar namespaces below?`
|
|
|
|
);
|
2022-09-12 11:00:37 +00:00
|
|
|
}
|
2022-10-28 06:49:28 +00:00
|
|
|
items.sort((a, b) => {
|
|
|
|
return a.label.localeCompare(b.label);
|
2022-09-12 11:00:37 +00:00
|
|
|
});
|
2022-10-28 06:49:28 +00:00
|
|
|
const main = items.find(item => {
|
|
|
|
return item.label === namespace;
|
2022-09-12 11:00:37 +00:00
|
|
|
});
|
2022-10-28 06:49:28 +00:00
|
|
|
items = items.filter(item => {
|
|
|
|
return item !== main;
|
|
|
|
});
|
|
|
|
target.push({
|
|
|
|
type: 'category',
|
|
|
|
label: namespace,
|
|
|
|
items,
|
|
|
|
link: main
|
|
|
|
? {
|
|
|
|
type: 'doc',
|
|
|
|
id: main.id,
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
});
|
|
|
|
categories.delete(namespace);
|
2022-09-12 11:00:37 +00:00
|
|
|
}
|
2022-10-28 06:49:28 +00:00
|
|
|
|
2023-04-06 12:23:10 +00:00
|
|
|
if (args.item.dirName === 'browsers-api') {
|
|
|
|
const order = [
|
|
|
|
'launch',
|
|
|
|
'install',
|
2023-05-22 12:03:11 +00:00
|
|
|
'uninstall',
|
2023-04-06 12:23:10 +00:00
|
|
|
'canDownload',
|
|
|
|
'createProfile',
|
|
|
|
'computeExecutablePath',
|
|
|
|
'computeSystemExecutablePath',
|
|
|
|
'resolveBuildId',
|
2023-05-22 12:03:11 +00:00
|
|
|
'getInstalledBrowsers',
|
|
|
|
'detectBrowserPlatform',
|
2023-04-06 12:23:10 +00:00
|
|
|
'BrowserPlatform',
|
|
|
|
'Browser',
|
|
|
|
'CLI',
|
|
|
|
];
|
|
|
|
const apiItem = sidebarItems.find(value => {
|
|
|
|
return value.type === 'doc' && value.label === 'API';
|
|
|
|
});
|
|
|
|
apiSidebarItems.push({
|
|
|
|
type: 'category',
|
|
|
|
label: 'API',
|
|
|
|
items: [],
|
|
|
|
link: apiItem
|
|
|
|
? {
|
|
|
|
type: 'doc',
|
|
|
|
id: apiItem.id,
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
});
|
|
|
|
const container = apiSidebarItems[apiSidebarItems.length - 1];
|
|
|
|
for (const namespace of order) {
|
|
|
|
addNamespace(namespace, container.items);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const order = [
|
|
|
|
// PuppeteerNode and Puppeteer go first as the entrypoints into
|
|
|
|
// the Puppeteer API.
|
|
|
|
'PuppeteerNode',
|
|
|
|
'Puppeteer',
|
|
|
|
'Browser',
|
|
|
|
'BrowserContext',
|
|
|
|
'Page',
|
|
|
|
'WebWorker',
|
|
|
|
'Accessibility',
|
|
|
|
'Keyboard',
|
|
|
|
'Mouse',
|
|
|
|
'Touchscreen',
|
|
|
|
'Tracing',
|
|
|
|
'FileChooser',
|
|
|
|
'Dialog',
|
|
|
|
'ConsoleMessage',
|
|
|
|
'Frame',
|
|
|
|
'JSHandle',
|
|
|
|
'ElementHandle',
|
|
|
|
'HTTPRequest',
|
|
|
|
'HTTPResponse',
|
|
|
|
'SecurityDetails',
|
|
|
|
'Target',
|
|
|
|
'CDPSession',
|
|
|
|
'Coverage',
|
|
|
|
'TimeoutError',
|
|
|
|
'EventEmitter',
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const namespace of order) {
|
|
|
|
addNamespace(namespace, apiSidebarItems);
|
|
|
|
}
|
2022-10-28 06:49:28 +00:00
|
|
|
}
|
|
|
|
const otherItems = [];
|
|
|
|
apiSidebarItems.push({
|
|
|
|
type: 'category',
|
|
|
|
label: 'Other',
|
|
|
|
items: otherItems,
|
|
|
|
collapsed: true,
|
|
|
|
});
|
|
|
|
const remaining = Array.from(categories.keys());
|
|
|
|
remaining.sort((a, b) => {
|
|
|
|
return a.localeCompare(b);
|
2022-09-12 11:00:37 +00:00
|
|
|
});
|
2022-10-28 06:49:28 +00:00
|
|
|
for (const namespace of remaining) {
|
2023-04-06 12:23:10 +00:00
|
|
|
if (namespace === 'API') {
|
|
|
|
continue;
|
|
|
|
}
|
2022-10-28 06:49:28 +00:00
|
|
|
addNamespace(namespace, otherItems);
|
2022-07-01 11:52:39 +00:00
|
|
|
}
|
2022-10-28 06:49:28 +00:00
|
|
|
return apiSidebarItems;
|
2022-07-01 11:52:39 +00:00
|
|
|
},
|
|
|
|
path: DOC_PATH,
|
|
|
|
routeBasePath: DOC_ROUTE_BASE_PATH,
|
2022-10-28 06:49:28 +00:00
|
|
|
sidebarPath: require.resolve('./sidebars.js'),
|
2022-07-01 11:52:39 +00:00
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
customCss: require.resolve('./src/css/custom.css'),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
themeConfig:
|
|
|
|
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
|
2022-10-28 06:49:28 +00:00
|
|
|
{
|
2022-11-03 08:40:12 +00:00
|
|
|
algolia: {
|
|
|
|
appId: 'DVKY664LG7',
|
|
|
|
apiKey: '4dac1ae64b623f1d33ae0b4ce0ff16a4',
|
|
|
|
indexName: 'pptr',
|
|
|
|
},
|
2022-07-01 11:52:39 +00:00
|
|
|
navbar: {
|
|
|
|
title: 'Puppeteer',
|
|
|
|
logo: {
|
|
|
|
alt: 'Puppeteer Logo',
|
|
|
|
src: 'https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png',
|
|
|
|
},
|
|
|
|
items: [
|
2022-10-28 06:49:28 +00:00
|
|
|
...[
|
|
|
|
{
|
|
|
|
type: 'doc',
|
|
|
|
docId: 'index',
|
|
|
|
label: 'Docs',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'docSidebar',
|
|
|
|
sidebarId: 'api',
|
2023-04-06 12:23:10 +00:00
|
|
|
label: 'Puppeteer API',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'docSidebar',
|
|
|
|
sidebarId: 'browsersApi',
|
|
|
|
label: '@puppeteer/browsers API',
|
2022-10-28 06:49:28 +00:00
|
|
|
},
|
|
|
|
].map(item => {
|
|
|
|
return Object.assign(item, {position: 'left'});
|
|
|
|
}),
|
|
|
|
...[
|
|
|
|
{
|
|
|
|
type: 'docsVersionDropdown',
|
|
|
|
dropdownActiveClassDisabled: true,
|
|
|
|
dropdownItemsAfter: [
|
|
|
|
{
|
|
|
|
type: 'html',
|
|
|
|
value: '<hr class="dropdown-separator">',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'html',
|
|
|
|
className: 'dropdown-archived-versions',
|
|
|
|
value: '<b>Archived versions</b>',
|
|
|
|
},
|
|
|
|
...archivedVersions.map(version => {
|
|
|
|
return {
|
|
|
|
label: version,
|
2023-10-12 13:04:29 +00:00
|
|
|
href: getApiUrl(`v${version}`),
|
2022-10-28 06:49:28 +00:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: 'https://github.com/puppeteer/puppeteer',
|
|
|
|
className: 'header-github-link',
|
|
|
|
'aria-label': 'GitHub repository',
|
|
|
|
},
|
|
|
|
].map(item => {
|
|
|
|
return Object.assign(item, {position: 'right'});
|
|
|
|
}),
|
2022-07-01 11:52:39 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
footer: {
|
|
|
|
style: 'dark',
|
|
|
|
links: [
|
|
|
|
{
|
|
|
|
title: 'Community',
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
label: 'Stack Overflow',
|
|
|
|
href: 'https://stackoverflow.com/questions/tagged/puppeteer',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Twitter',
|
|
|
|
href: 'https://twitter.com/chromedevtools',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'YouTube',
|
|
|
|
href: 'https://goo.gle/devtools-youtube',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
copyright: `Copyright © ${new Date().getFullYear()} Google, Inc.`,
|
|
|
|
},
|
|
|
|
prism: {
|
|
|
|
theme: lightCodeTheme,
|
|
|
|
darkTheme: darkCodeTheme,
|
2023-11-29 12:06:05 +00:00
|
|
|
additionalLanguages: ['bash', 'diff', 'json'],
|
2022-07-01 11:52:39 +00:00
|
|
|
},
|
2022-10-28 06:49:28 +00:00
|
|
|
},
|
2022-07-01 11:52:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = config;
|