如何在Chrome扩展中加载Google Analytics和Facebook SDK? [英] How to load Google Analytics and Facebook SDK in chrome extension?

本文介绍了如何在Chrome扩展中加载Google Analytics和Facebook SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kango框架开发一个Chrome扩展,并且我同时使用Google Analytics和Facebook SDK。我编辑了清单文件以包含follwoign

 content_security_policy:script-src'self'https:// ssl。 google-analytics.com https://connect.facebook.net; object-src'self'; default-src'self''unsafe-eval'chrome-extension-resource:https://*.facebook.net https: //*.facebook.com; style-src'self''unsafe-inline'chrome-extension-resource:https://*.facebook.net https://*.facebook.com; frame-src'self' 'unsafe-inline'chrome-extension-resource:https://*.facebook.net https://*.facebook.com

但它不起作用!我得到以下错误:
$ b $ pre $ 拒绝将字符串评估为JavaScript,因为'unsafe-eval'不是允许的来源以下内容安全策略指令中的脚本:script-src'self'https://ssl.google-analytics.com https://connect.facebook.net。


解决方案

更改 script-src 指令在最后有'unsafe-eval'

  script-src'self'https://ssl.google-analytics.com https://connect.facebook.net'unsafe-eval'; 

请注意,这会降低扩展的安全性,因为可以执行随机的JavaScript字符串。 p>

I'm developing a chrome extension using Kango framework, and I waned to use both Google Analytics and facebook SDK. I edited the manifest file to include the follwoign

"content_security_policy": "script-src 'self' https://ssl.google-analytics.com https://connect.facebook.net; object-src 'self'; default-src 'self' 'unsafe-eval' chrome-extension-resource: https://*.facebook.net https://*.facebook.com; style-src 'self' 'unsafe-inline' chrome-extension-resource: https://*.facebook.net https://*.facebook.com; frame-src 'self' 'unsafe-inline' chrome-extension-resource: https://*.facebook.net https://*.facebook.com"

But it doesn't work! and I'm getting the following error

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' https://ssl.google-analytics.com https://connect.facebook.net".

解决方案

Change the script-src directive to have 'unsafe-eval' at the end.

script-src 'self' https://ssl.google-analytics.com https://connect.facebook.net 'unsafe-eval';

Note that this will lower the security of your extension as random strings of JavaScript can be executed.

这篇关于如何在Chrome扩展中加载Google Analytics和Facebook SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆