1(self.webpackChunkinappweview_website=self.webpackChunkinappweview_website||[]).push([["7814"],{9367:function(e,t,o){"use strict";o.r(t),o.d(t,{metadata:()=>i,contentTitle:()=>d,default:()=>f,assets:()=>u,toc:()=>b,frontMatter:()=>p});var i=JSON.parse('{"id":"webview/process-global-config","title":"Process Global Config","description":"Process Global Configuration for Android WebView.","source":"@site/docs/webview/process-global-config.mdx","sourceDirName":"webview","slug":"/webview/process-global-config","permalink":"/docs/webview/process-global-config","draft":false,"unlisted":false,"editUrl":"https://github.com/pichillilorenzo/inappwebview.dev/tree/main/docs/webview/process-global-config.mdx","tags":[],"version":"current","sidebarPosition":12,"frontMatter":{"title":"Process Global Config","sidebar_position":12,"date":"2023-11-30T10:00:00.000Z","description":"Process Global Configuration for Android WebView."},"sidebar":"tutorialSidebar","previous":{"title":"Keep Alive","permalink":"/docs/webview/keep-alive"},"next":{"title":"In-App Browsers","permalink":"/docs/category/in-app-browsers"}}'),a=o("5893"),n=o("65"),r=o("6312"),l=o.n(r),s=o("7360"),c=o("5479");let p={title:"Process Global Config",sidebar_position:12,date:new Date("2023-11-30T10:00:00.000Z"),description:"Process Global Configuration for Android WebView."},d=void 0,u={},b=[{value:"Basic Usage",id:"basic-usage",level:2}];function h(e){let t={a:"a",code:"code",h2:"h2",p:"p",pre:"pre",...(0,n.a)(),...e.components},{Head:o}=t;return!o&&function(e,t){throw Error("Expected "+(t?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Head",!0),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(o,{children:(0,a.jsxs)("title",{children:["WebView Process Global Config | ",l().title]})}),"\n",(0,a.jsx)(c.j,{platforms:[s.t.Android]}),"\n",(0,a.jsx)(t.p,{children:"Process Global Configuration for Android-specific WebView.\nWebView has some process-global configuration parameters that cannot be changed once WebView has been loaded.\nThis class allows apps to set these parameters."}),"\n",(0,a.jsxs)(t.p,{children:["If it is used, the configuration should be set and ",(0,a.jsx)(t.code,{children:"apply"})," should be called prior to loading WebView\ninto the calling process.\nMost of the methods in ",(0,a.jsx)(t.code,{children:"android.webkit"})," and ",(0,a.jsx)(t.code,{children:"androidx.webkit"})," packages load WebView,\nso the configuration should be applied before calling any of these methods."]}),"\n",(0,a.jsx)(t.h2,{id:"basic-usage",children:"Basic Usage"}),"\n",(0,a.jsxs)(t.p,{children:[(0,a.jsx)(t.code,{children:"apply"})," can only be called once.\nTrying to call it more than once, will result in a ",(0,a.jsx)(t.code,{children:"PlatformException"}),"."]}),"\n",(0,a.jsx)(t.p,{children:"Only a single thread should access this class at a given time."}),"\n",(0,a.jsx)(t.p,{children:"The configuration should be set up as early as possible during application startup,\nto ensure that it happens before any other thread can call a method that loads WebView."}),"\n",(0,a.jsx)(t.p,{children:"The following code configures the data and cache directory base path and the data directory suffix\nthat WebView uses and then applies the configuration.\nWebView uses this configuration when it is loaded."}),"\n",(0,a.jsx)(t.p,{children:"Before applying the configuration, you should check if the related Android WebView startup feature is\ncurrently supported or not."}),"\n",(0,a.jsxs)(t.p,{children:["In this example, I'm also using the ",(0,a.jsx)(t.a,{href:"https://pub.dev/packages/path_provider",children:"path_provider"}),"\nplugin to get the Application Documents Directory as the directory base path."]}),"\n",(0,a.jsx)(t.p,{children:"Example:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-dart",children:"import 'package:flutter/foundation.dart';\nimport 'package:flutter/material.dart';\nimport 'package:flutter_inappwebview/flutter_inappwebview.dart';\nimport 'package:path_provider/path_provider.dart';\n\nFuture main() async {\n WidgetsFlutterBinding.ensureInitialized();\n\n final dataDirectorySuffix = (await WebViewFeature.isStartupFeatureSupported(\n WebViewFeature.STARTUP_FEATURE_SET_DATA_DIRECTORY_SUFFIX))\n ? 'suffix_inappwebviewexample'\n : null;\n\n final appDocsPath = (await getApplicationDocumentsDirectory()).absolute.path;\n\n final directoryBasePaths = (await WebViewFeature.isStartupFeatureSupported(\n WebViewFeature.STARTUP_FEATURE_SET_DIRECTORY_BASE_PATHS))\n ? ProcessGlobalConfigDirectoryBasePaths(\n cacheDirectoryBasePath: '$appDocsPath/inappwebviewexample/cache',\n dataDirectoryBasePath: '$appDocsPath/inappwebviewexample/data')\n : null;\n\n try {\n // call apply before any API related to Android WebViews\n await ProcessGlobalConfig.instance().apply(\n settings: ProcessGlobalConfigSettings(\n dataDirectorySuffix: dataDirectorySuffix,\n directoryBasePaths: directoryBasePaths));\n } catch (e) {\n // use try/catch if you are calling more than once\n // for example, when hot restarting your Flutter App.\n print(e);\n }\n\n if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {\n // for example, this API is related to Android WebViews.\n // if you call this method before ProcessGlobalConfig.apply,\n // the apply method won't work\n await InAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode);\n }\n\n runApp(const MaterialApp(home: MyApp()));\n}\n"})})]})}function f(e={}){let{wrapper:t}={...(0,n.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},3618:function(e,t,o){"use strict";o.r(t),o.d(t,{default:function(){return i}});let i={plain:{color:"#F8F8F2",backgroundColor:"#282A36"},styles:[{types:["prolog","constant","builtin"],style:{color:"rgb(189, 147, 249)"}},{types:["inserted","function"],style:{color:"rgb(80, 250, 123)"}},{types:["deleted"],style:{color:"rgb(255, 85, 85)"}},{types:["changed"],style:{color:"rgb(255, 184, 108)"}},{types:["punctuation","symbol"],style:{color:"rgb(248, 248, 242)"}},{types:["string","char","tag","selector"],style:{color:"rgb(255, 121, 198)"}},{types:["keyword","variable"],style:{color:"rgb(189, 147, 249)",fontStyle:"italic"}},{types:["comment"],style:{color:"rgb(98, 114, 164)"}},{types:["attr-name"],style:{color:"rgb(241, 250, 140)"}}]}},7694:function(e,t,o){"use strict";o.r(t),o.d(t,{default:function(){return i}});let i={plain:{color:"#393A34",backgroundColor:"#f6f8fa"},styles:[{types:["comment","prolog","doctype","cdata"],style:{color:"#999988",fontStyle:"italic"}},{types:["namespace"],style:{opacity:.7}},{types:["string","attr-value"],style:{color:"#e3116c"}},{types:["punctuation","operator"],style:{color:"#393A34"}},{types:["entity","url","symbol","number","boolean","variable","constant","property","regex","inserted"],style:{color:"#36acaa"}},{types:["atrule","keyword","attr-name","selector"],style:{color:"#00a4db"}},{types:["function","deleted","tag"],style:{color:"#d73a49"}}
1,{types:["function-variable"],style:{color:"#6f42c1"}},{types:["tag","selector","keyword"],style:{color:"#00009f"}}]}},6312:function(e,t,o){let i=o(7694),a=o(3618),n={future:{experimental_faster:!0},title:"InAppWebView",tagline:"Flutter InAppWebView",url:"https://inappwebview.dev",baseUrl:"/",onBrokenLinks:"throw",onBrokenMarkdownLinks:"warn",favicon:"img/favicon.ico",organizationName:"pichillilorenzo",projectName:"flutter_inappwebview",i18n:{defaultLocale:"en",locales:["en"]},presets:[["classic",{docs:{sidebarPath:517,editUrl:"https://github.com/pichillilorenzo/inappwebview.dev/tree/main/",lastVersion:"current",sidebarItemsGenerator:async e=>{let{defaultSidebarItemsGenerator:t,...o}=e;return await t(o)},versions:{current:{label:"6.x.x"},"5.x.x":{banner:"none"}}},blog:{showReadingTime:!0,editUrl:"https://github.com/pichillilorenzo/inappwebview.dev/tree/main/"},theme:{customCss:7686},gtag:{trackingID:"G-YKDBPM0BJ9",anonymizeIP:!0}}]],themeConfig:{metadata:[{name:"keywords",content:"webview, inappwebview, inappbrowser, flutter, chrome, safari, browser"}],algolia:{appId:"MJATJYT1MX",apiKey:"1b4f2aea5c887ceeda4ed9fe83c426b1",indexName:"inappwebview",contextualSearch:!0,searchPagePath:"search",debug:!1},navbar:{title:"",logo:{alt:"Flutter InAppWebView Logo",src:"img/logo.svg"},items:[{type:"docsVersionDropdown",position:"left"},{to:"/blog",label:"Blog",position:"left"},{to:"https://pub.dartlang.org/packages/flutter_inappwebview",label:"Pub.dev",position:"left"},{label:"API Reference",position:"left",items:[{to:"https://pub.dev/documentation/flutter_inappwebview/latest/",label:"6.x.x"},{to:"https://pub.dev/documentation/flutter_inappwebview/5.8.0/",label:"5.x.x"}]},{to:"/showcase",label:"Showcase",position:"left"},{to:"/donate",label:"Donate",position:"left",className:"btn-donate"},{type:"search",position:"right"},{href:"https://github.com/pichillilorenzo/flutter_inappwebview",label:"GitHub",position:"right"}]},footer:{style:"dark",links:[{title:"Docs",items:[{label:"Getting Started",to:"/docs/intro"},{label:"Project Examples",href:"/docs/project-examples"},{label:"Migration Guide from 5.x.x",to:"/docs/migration-guide"}]},{title:"Resources",items:[{label:"Blog",to:"/blog"},{label:"Medium",to:"https://medium.com/@pichillilorenzo"},{label:"Stack Overflow",href:"https://stackoverflow.com/questions/tagged/flutter-inappwebview?tab=Newest"}]},{title:"More",items:[{label:"Privacy Policy",to:"https://www.iubenda.com/privacy-policy/83191229"},{label:"Cookie Policy",to:"https://www.iubenda.com/privacy-policy/83191229/cookie-policy"},{label:"GitHub",href:"https://github.com/pichillilorenzo/flutter_inappwebview"}]}],copyright:`Copyright \xa9 ${new Date().getFullYear()} Flutter InAppWebView, Inc. Built with Docusaurus.<br /> 2 Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.`},prism:{theme:i,darkTheme:a,additionalLanguages:["dart"]}}};e.exports=n},517:function(e){e.exports={tutorialSidebar:[{type:"autogenerated",dirName:"."}]}},7360:function(e,t,o){"use strict";o.d(t,{t:function(){return a}});var i,a=((i={}).Android="Android",i.iOS="iOS",i.macOS="macOS",i.Windows="Windows",i.Linux="Linux",i.Web="Web",i)},5479:function(e,t,o){"use strict";o.d(t,{j:()=>n});var i=o("5893");o("7294");let a=e=>{let{text:t,type:o="info"}=e;return(0,i.jsx)("span",{className:"badge badge--"+o,style:{lineHeight:"initial"},children:t})},n=e=>{let{platforms:t}=e;return(0,i.jsxs)("p",{style:{display:"flex",flexDirection:"row",gap:"5px"},children:[(0,i.jsx)("strong",{children:"Supported Platforms: "}),t.map((e,t)=>{let o="object"==typeof e?e:null;return(0,i.jsx)(a,{text:"string"==typeof e?e:`${o.platform} ${o.version?o.version+"+":""}`.trim()},t)})]})}},65:function(e,t,o){"use strict";o.d(t,{Z:function(){return l},a:function(){return r}});var i=o(7294);let a={},n=i.createContext(a);function r(e){let t=i.useContext(n);return i.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),i.createElement(n.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.