mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
1 line
16 KiB
JavaScript
1 line
16 KiB
JavaScript
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[84641],{3905:(e,t,n)=>{n.d(t,{Zo:()=>c,kt:()=>f});var r=n(67294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var u=r.createContext({}),p=function(e){var t=r.useContext(u),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},c=function(e){var t=p(e.components);return r.createElement(u.Provider,{value:t},e.children)},s={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,u=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),m=p(n),f=a,d=m["".concat(u,".").concat(f)]||m[f]||s[f]||o;return n?r.createElement(d,i(i({ref:t},c),{},{components:n})):r.createElement(d,i({ref:t},c))}));function f(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var l={};for(var u in t)hasOwnProperty.call(t,u)&&(l[u]=t[u]);l.originalType=e,l.mdxType="string"==typeof e?e:a,i[1]=l;for(var p=2;p<o;p++)i[p]=n[p];return r.createElement.apply(null,i)}return r.createElement.apply(null,n)}m.displayName="MDXCreateElement"},16302:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>_,contentTitle:()=>I,default:()=>M,frontMatter:()=>D,metadata:()=>V,toc:()=>A});var r=n(67294),a=n(3905),o=n(86010),i=n(6379),l=n(76775),u=n(47348),p=n(83928),c=n(76632);function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})),e}function f(e){return function(e){var t,n;return null!==(n=null===(t=r.Children.map(e,(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})))||void 0===t?void 0:t.filter(Boolean))&&void 0!==n?n:[]}(e).map((({props:{value:e,label:t,attributes:n,default:r}})=>({value:e,label:t,attributes:n,default:r})))}function d(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=null!=t?t:f(n);return function(e){const t=(0,p.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e}),[t,n])}function b({value:e,tabValues:t}){return t.some((t=>t.value===e))}function g({queryString:e=!1,groupId:t}){const n=(0,l.k6)(),a=function({queryString:e=!1,groupId:t}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!t)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return null!=t?t:null}({queryString:e,groupId:t}),o=(0,u._X)(a),i=(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(n.location.search);t.set(a,e),n.replace(m(function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter((function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})))),r.forEach((function(t){s(e,t,n[t])}))}return e}({},n.location),{search:t.toString()}))}),[a,n]);return[o,i]}function y(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,o=d(e),[i,l]=(0,r.useState)((()=>function({defaultValue:e,tabValues:t}){if(0===t.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!b({value:e,tabValues:t}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}var n;const r=null!==(n=t.find((e=>e.default)))&&void 0!==n?n:t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[u,p]=g({queryString:n,groupId:a}),[s,m]=function({groupId:e}){const t=function(e){return e?`docusaurus.tab.${e}`:null}(e),[n,a]=(0,c.Nk)(t);return[n,(0,r.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:a}),f=(()=>{const e=null!=u?u:s;return b({value:e,tabValues:o})?e:null})();(0,r.useLayoutEffect)((()=>{f&&l(f)}),[f]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!b({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),p(e),m(e)}),[p,m,o]),tabValues:o}}var h=n(30358);const v="tabList__CuJ",k="tabItem_LNqP";function O(){return O=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},O.apply(this,arguments)}function w({className:e,block:t,selectedValue:n,selectValue:a,tabValues:l}){const u=[],{blockElementScrollPositionUntilNextRender:p}=(0,i.o5)(),c=e=>{const t=e.currentTarget,r=u.indexOf(t),o=l[r].value;o!==n&&(p(t),a(o))},s=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=u.indexOf(e.currentTarget)+1;var n;t=null!==(n=u[r])&&void 0!==n?n:u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;var r;t=null!==(r=u[n])&&void 0!==r?r:u[u.length-1];break}}null==t||t.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":t},e)},l.map((({value:e,label:t,attributes:a})=>r.createElement("li",O({role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,key:e,ref:e=>u.push(e),onKeyDown:s,onClick:c},a,{className:(0,o.Z)("tabs__item",k,null==a?void 0:a.className,{"tabs__item--active":n===e})}),null!=t?t:e))))}function N({lazy:e,children:t,selectedValue:n}){const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(e){const e=a.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},a.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==n}))))}function j(e){const t=y(e);return r.createElement("div",{className:(0,o.Z)("tabs-container",v)},r.createElement(w,O({},e,t)),r.createElement(N,O({},e,t)))}function C(e){const t=(0,h.Z)();return r.createElement(j,O({key:String(t)},e))}const P="tabItem_Ymn6";function E(){return E=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},E.apply(this,arguments)}function T({children:e,hidden:t,className:n}){return r.createElement("div",E({role:"tabpanel",className:(0,o.Z)(P,n)},{hidden:t}),e)}function x(){return x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},x.apply(this,arguments)}function S(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}const D={},I="Configuration",V={unversionedId:"guides/configuration",id:"version-19.11.1/guides/configuration",title:"Configuration",description:"All defaults in Puppeteer can be customized in two ways:",source:"@site/versioned_docs/version-19.11.1/guides/configuration.mdx",sourceDirName:"guides",slug:"/guides/configuration",permalink:"/guides/configuration",draft:!1,tags:[],version:"19.11.1",frontMatter:{},sidebar:"docs",previous:{title:"Guides",permalink:"/category/guides"},next:{title:"Query Selectors",permalink:"/guides/query-selectors"}},_={},A=[{value:"Configuration files",id:"configuration-files",level:2},{value:"Examples",id:"examples",level:3},{value:"Changing the default cache directory",id:"changing-the-default-cache-directory",level:4},{value:"Enabling experiments",id:"enabling-experiments",level:4},{value:"Environment variables",id:"environment-variables",level:2}],q={toc:A};function M(e){var{components:t}=e,n=S(e,["components"]);return(0,a.kt)("wrapper",x({},q,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",x({},{id:"configuration"}),"Configuration"),(0,a.kt)("p",null,"All defaults in Puppeteer can be customized in two ways:"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",x({parentName:"li"},{href:"#configuration-files"}),"Configuration files")," (",(0,a.kt)("strong",{parentName:"li"},"recommended"),")"),(0,a.kt)("li",{parentName:"ol"},(0,a.kt)("a",x({parentName:"li"},{href:"#environment-variables"}),"Environment variables"))),(0,a.kt)("admonition",x({},{type:"caution"}),(0,a.kt)("p",{parentName:"admonition"},"Note that some options are only customizable through environment variables (such\nas ",(0,a.kt)("inlineCode",{parentName:"p"},"HTTPS_PROXY"),").")),(0,a.kt)("admonition",x({},{type:"caution"}),(0,a.kt)("p",{parentName:"admonition"},"Puppeteer's configuration files and environment variables are ignored by ",(0,a.kt)("inlineCode",{parentName:"p"},"puppeteer-core"),".")),(0,a.kt)("h2",x({},{id:"configuration-files"}),"Configuration files"),(0,a.kt)("p",null,"Configuration files are the ",(0,a.kt)("strong",{parentName:"p"},"recommended")," choice for configuring Puppeteer.\nPuppeteer will look up the file tree for any of the following formats:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},".puppeteerrc.cjs"),","),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},".puppeteerrc.js"),","),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},".puppeteerrc")," (YAML/JSON),"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},".puppeteerrc.json"),","),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},".puppeteerrc.yaml"),","),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"puppeteer.config.js"),", and"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"puppeteer.config.cjs"))),(0,a.kt)("p",null,"Puppeteer will also read a ",(0,a.kt)("inlineCode",{parentName:"p"},"puppeteer")," key from your application's\n",(0,a.kt)("inlineCode",{parentName:"p"},"package.json"),"."),(0,a.kt)("p",null,"See the ",(0,a.kt)("a",x({parentName:"p"},{href:"../api/puppeteer.configuration"}),(0,a.kt)("inlineCode",{parentName:"a"},"Configuration"))," interface for possible\noptions."),(0,a.kt)("admonition",x({},{type:"caution"}),(0,a.kt)("p",{parentName:"admonition"},"After adding a configuration file, you may need to remove and reinstall\n",(0,a.kt)("inlineCode",{parentName:"p"},"puppeteer")," for it to take effect if the changes affect installation.")),(0,a.kt)("h3",x({},{id:"examples"}),"Examples"),(0,a.kt)("h4",x({},{id:"changing-the-default-cache-directory"}),"Changing the default cache directory"),(0,a.kt)("p",null,"Starting in v19.0.0, Puppeteer stores browsers in ",(0,a.kt)("inlineCode",{parentName:"p"},"~/.cache/puppeteer")," to\nglobally cache browsers between installation. This can cause problems if\n",(0,a.kt)("inlineCode",{parentName:"p"},"puppeteer")," is packed during some build step and moved to a fresh location. The\nfollowing configuration can solve this issue (reinstall ",(0,a.kt)("inlineCode",{parentName:"p"},"puppeteer")," to take\neffect):"),(0,a.kt)("pre",null,(0,a.kt)("code",x({parentName:"pre"},{className:"language-js",metastring:'title="project-directory/.puppeteerrc.cjs"',title:'"project-directory/.puppeteerrc.cjs"'}),"const {join} = require('path');\n\n/**\n * @type {import(\"puppeteer\").Configuration}\n */\nmodule.exports = {\n // Changes the cache location for Puppeteer.\n cacheDirectory: join(__dirname, '.cache', 'puppeteer'),\n};\n")),(0,a.kt)("admonition",x({},{type:"note"}),(0,a.kt)("p",{parentName:"admonition"},"Notice this is only possible with CommonJS configuration files as information\nabout the ambient environment is needed (in this case, ",(0,a.kt)("inlineCode",{parentName:"p"},"__dirname"),").")),(0,a.kt)("h4",x({},{id:"enabling-experiments"}),"Enabling experiments"),(0,a.kt)("p",null,"By default, experiments are turned off, but they can be individually turned on\nusing the ",(0,a.kt)("a",x({parentName:"p"},{href:"../api/puppeteer.configuration"}),(0,a.kt)("inlineCode",{parentName:"a"},"experiments"))," key."),(0,a.kt)("p",null,"For example, if you want to enable ARM-native macOS chromium, you can use"),(0,a.kt)(C,{mdxType:"Tabs"},(0,a.kt)(T,{value:"CommonJS",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",x({parentName:"pre"},{className:"language-js",metastring:'title=".puppeteerrc.cjs"',title:'".puppeteerrc.cjs"'}),'/**\n * @type {import("puppeteer").Configuration}\n */\nmodule.exports = {\n experiments: {\n macArmChromiumEnabled: true,\n },\n};\n'))),(0,a.kt)(T,{value:"JSON",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",x({parentName:"pre"},{className:"language-json",metastring:'title=".puppeteerrc.json"',title:'".puppeteerrc.json"'}),'{\n "experiments": {\n "macArmChromiumEnabled": true\n }\n}\n'))),(0,a.kt)(T,{value:"YAML",mdxType:"TabItem"},(0,a.kt)("pre",null,(0,a.kt)("code",x({parentName:"pre"},{className:"language-yaml",metastring:'title=".puppeteerrc.yaml"',title:'".puppeteerrc.yaml"'}),"experiments:\n macArmChromiumEnabled: true\n")))),(0,a.kt)("h2",x({},{id:"environment-variables"}),"Environment variables"),(0,a.kt)("p",null,"Along with configuration files, Puppeteer looks for certain\n",(0,a.kt)("a",x({parentName:"p"},{href:"https://en.wikipedia.org/wiki/Environment_variable"}),"environment variables")," for\ncustomizing behavior. Environment variables will always override configuration\nfile options when applicable."),(0,a.kt)("p",null,"The following options are ",(0,a.kt)("em",{parentName:"p"},"environment-only")," options"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"HTTP_PROXY"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"HTTPS_PROXY"),", ",(0,a.kt)("inlineCode",{parentName:"li"},"NO_PROXY")," - defines HTTP proxy settings that are\nused to download and run the browser.")),(0,a.kt)("p",null,"All other options can be found in the documentation for the\n",(0,a.kt)("a",x({parentName:"p"},{href:"../api/puppeteer.configuration"}),(0,a.kt)("inlineCode",{parentName:"a"},"Configuration"))," interface."))}M.isMDXComponent=!0}}]); |