I tried to use tensorflow local model in my chrome extension. In contentScript
:
import * as tf from '@tensorflow/tfjs';
const MODEL_URL = './model/model.json';
const model = tf.load_model(MODEL_URL);
model.run("text");
My manifest.json
:
"content_security_policy": {
"extension_pages": "script-src 'self' http://localhost; object-src 'self';"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_title": "My extension",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"history",
"background",
"webNavigation",
"activeTab",
"storage"
],
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"run_at": "document_start",
"js": [
"contentScript.js"
]
}
]
But I got error Uncaught EvalError: 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'".
My package.json
:
{
"name": "my-extension",
"version": "0.1.0",
"description": "My Chrome Extension",
"private": true,
"scripts": {
"watch": "webpack --mode=development --watch --config config/webpack.config.js",
"build": "webpack --mode=production --config config/webpack.config.js"
},
"devDependencies": {
"copy-webpack-plugin": "^6.4.1",
"css-loader": "^4.3.0",
"file-loader": "^6.2.0",
"mini-css-extract-plugin": "^0.10.1",
"size-plugin": "^2.0.2",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@tensorflow/tfjs": "^3.16.0",
"@tensorflow/tfjs-node": "^3.16.0"
}
}
What should be the proper way to using local model?
from Error when importing '@tensorflow/tfjs' to use local model in Chrome extension
No comments:
Post a Comment