簡體   English   中英

適用於Cordova Hybrid App的CORS政策

[英]CORS policy applied to cordova hybrid app

在我的cordova應用程序中,我使用$ .ajax請求訪問外部api(在我的服務器上)。 我已經安裝了cordova-plugin-whitelist。

但是,每當第一次運行全新安裝的應用程序時,或者在清理cach +數據之后,我都會收到以下錯誤之一:

1:當我啟用標頭('Access-Control-Allow-Origin:*')時;

Access to XMLHttpRequest at 'https://myapi_adress' from origin 'file://' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

2:禁用

Access to XMLHttpRequest at 'https://myapi_adress' from origin 'file://' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

重新啟動設備上的應用程序后,所有運行正常。 來自設備的每個請求包含

 'Origin' => 'file://'

但是它僅在首次運行時或清除應用程序的緩存和數據后才阻塞。

看起來白名單插件在第一次運行或清除緩存后沒有應用/正常工作。

有什么建議么?

好的,這是答案:

最近的chrome / WebView更新導致首次啟動/ clear_cache啟動時配置錯誤( https://bugs.chromium.org/p/chromium/issues/detail?id=991107 ):

[摘要] WebView 76似乎僅在第一次啟動時就采用了錯誤的配置。 解決方法是,一旦WebView重新啟動,它就可以繼續正常工作。 注意:-請檢查左上角的星形圖標以提高優先級(很多“我也是”評論隱藏了有益的反饋)-修復程序已合並到release分支,但暫時未計划進行更新(#c21) ,#c23)-解決方法信息(確保它對您安全):#c19,#c37對於WebView Beta用戶:如果您處於Beta頻道,可以幫助我們確認您的應用程序是否可以與WebView 77 beta一起使用? 我們已經計划在WebView 77上啟用OOR-CORS。因此,這對降低m77穩定升級引起回歸問題的風險非常有幫助。 (注意:尚未推出WebView 77 Beta)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM