Bug description:
I'm following the react-native-webview documentation and passing cookies, but when debugging, it appears that cookies are not sent on the first WebView call (which is the desired time).
const App = () => {
return (
<WebView
source={{
uri: '',
headers: {
Cookie: 'cookie1=asdf; cookie2=dfasdfdas',
},
}}
sharedCookiesEnabled={true}
/>
);
};
Environment:
- OS: IOS and ANDROID
- react-native version: 0.75.4
- react-native-webview version: 11.22.7
Bug description:
I'm following the react-native-webview documentation and passing cookies, but when debugging, it appears that cookies are not sent on the first WebView call (which is the desired time).
const App = () => {
return (
<WebView
source={{
uri: 'http://example',
headers: {
Cookie: 'cookie1=asdf; cookie2=dfasdfdas',
},
}}
sharedCookiesEnabled={true}
/>
);
};
Environment:
- OS: IOS and ANDROID
- react-native version: 0.75.4
- react-native-webview version: 11.22.7
1 Answer
Reset to default 0as per the doc in react native webview, you can use injectedJavaScriptBeforeContentLoaded prop.
This prop will execute before the web page loads for the first time
example
const App = () => {
const runFirst = `
cookie1=asdf;
cookie2=asdf;
`;
return (
<WebView
source={{ uri: 'http://example' }}
injectedJavaScriptBeforeContentLoaded={runFirst}
sharedCookiesEnabled={true}
/>
);
};