當我在 Eclipse 中使用超級開發模式對其進行測驗時,在瀏覽器中的代碼中出現以下錯誤:
wmsapp.nocache.js:131 Refused to load the script 'http://127.0.0.1:9876/wmsapp/5B051516607B4217EFF2D0B7FB10B220.cache.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' http://127.0.0.1:9876/recompile-requester/wmsapp http://127.0.0.1:9876/recompile/wmsapp http://127.0.0.1:9876/wmsapp/wmsapp.nocache.js". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
installCode @ wmsapp.nocache.js:131
顯然,在未來的測驗中,5B051516607B4217EFF2D0B7FB10B220.cache.js會發生變化。我知道這一點是因為在之前的測驗中我有不同的檔案參考。對于另一個 GWT 專案,我沒有這個問題。那么我做錯了什么?我無法將此添加到內容安全策略中,因為它會更改。有任何想法嗎?
真正奇怪的是,我在源目錄結構中的任何地方都看不到這個檔案,即使在其他檔案中也是如此。今天早些時候,為了進行不同的測驗,我得到了一個不同的檔案,我確實看到它在另一個檔案中被參考,但沒有找到檔案本身。對于這個最新的測驗,它位于 temp 檔案夾下,C:\Users\<userid>\AppData\Local\Temp\gwt-codeserver-3014931782125410745.tmp我認為這是有道理的,并確認了它為什么會因每個測驗而改變。
當前的安全內容策略:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' http://127.0.0.1:9876; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://127.0.0.1:9876/recompile-requester/wmsapp http://127.0.0.1:9876/recompile/wmsapp http://127.0.0.1:9876/wmsapp/wmsapp.nocache.js">
uj5u.com熱心網友回復:
根據您使用的 GWT 版本,GWT 通常會創建幾個 JS 檔案。IIRC,沒有任何改變,你有 - 使用持久的 GWT 版本 - 5 個排列。這些是*.nochache.js正在加載的具有神秘名稱的檔案。
這些排列將從代碼服務器加載。通過在 Content-Security-Policy 標簽內定義檔案,您可以定義可以加載的檔案。而且因為檔案名總是改變,你沒有機會添加它們。
那么,為什么不使用:
script-src http://127.0.0.1:9876
如這里第三個示例中所述。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/412026.html
標籤:
