最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

react native - Cookies are not sent in webview headers - Stack Overflow

programmeradmin5浏览0评论

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
Share Improve this question asked yesterday Ronald SilvaRonald Silva 111 bronze badge New contributor Ronald Silva is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

as 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}
    />
  );
};
发布评论

评论列表(0)

  1. 暂无评论