I am trying to use tensorflowjs in my chrome extension. But,I am not able to figure out how to do it. I tried to download tf.min.js file by going to this link : https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js I included this file in the manifest file:
{
"name": "Getting Started Example",
"version": "1.0",
"description": "Build an Extension!",
"permissions": ["activeTab", "declarativeContent", "storage","tabs", "<all_urls>"],
"options_page": "options.html",
"background": {
"scripts": ["tf.min.js", "background.js"],
"persistent": false
},
"page_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
}
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
As you can see, I've also set content_security_policy to script-src 'self' 'unsafe-eval'; object-src 'self'. But, I am always getting multiple warnings in the tf.min.js and errors in the content.js file(Registration of backend webgl failed), which is:
// Copyright 2018 The Chromium Authors. All rights reserved.
import * as tf from '@tensorflow/tfjs';
bth1.onclick = function scrapeThePage() {
// Keep this function isolated - it can only call methods you set up in content scripts
var htmlCode = document.documentElement.outerHTML;
var btn = document.getElementById("mybtn1");
var keywords = ['a','b','c'];
var arr = [];
for(let i = 0; i < keywords.length; i++){
var reg = new RegExp(`${keywords[i]}`,'g')
arr[i] = Math.log(1+(htmlCode.match(reg) || []).length);
}
btn.innerText(arr)
}
Am I downloading the file from the wrong website? How do I use tensorflowjs in chrome extensions?