Я установил CSP моего расширения, чтобы разрешить загрузку с localhost
(теоретически):
"content_security_policy": "script-src 'self' 'unsafe-eval' https://localhost:* ws://localhost:* https://*.mysite.com; object-src 'self'",
У меня есть web_accessible_resource
, который пытается загрузить и выполнить удаленный скрипт:
<html>
<head>
<title>Sign in</title>
</head>
<body>
<script src="./auth.js"></script>
</body>
</html>
(Упрощенное) содержание auth.js
:
(function(doc, script) {
script = doc.createElement('script')
script.type = 'text/javascript'
script.async = true
script.src = 'https://localhost:3333/remote-server/auth.js'
doc.getElementsByTagName('head')[0].appendChild(script)
}(document))
Однако я получаю следующую ошибку:
Refused to load the script 'https://localhost:3333/remote-server/auth.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
Что, похоже, не соблюдает CSP расширения. Я попытался добавить следующий заголовок непосредственно в HTML, но все равно без радости.
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-eval' https://localhost:* ws://localhost:* https://*.mysite.com">
Есть ли какое-то другое место, где мне нужно указать CSP?
ОБНОВЛЕНИЕ
Изменение HTML-кода ресурса для прямой загрузки удаленного скрипта также не решило проблему:
<html>
<head>
<title>Sign in</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval' https://localhost:* ws://localhost:* https://*.mysite.com">
</head>
<body>
<script src="https://localhost:3333/remote-server/auth.js"></script>
</body>
</html>
Все еще приводит к:
Refused to load the script 'https://localhost:3333/remote-server/auth.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
Который до сих пор не имеет ссылки на содержимое тега <meta>
ОБНОВЛЕНИЕ 2
Страница загружается через
chrome.windows.create({
url: 'chrome-extension://my-extension/auth.html',
type: 'popup',
height: 680,
width: 500
}, (windw) => console.log(windw))
web_accessible_resource
s? Если CSP расширения не применяется, что применяется? - person Jonathan Bender   schedule 04.08.2016