Chrome extension

691 views
Skip to first unread message

Arman Oganesian

unread,
Aug 15, 2018, 12:41:15 PM8/15/18
to TensorFlow.js Discussion
Can i run tfjs completely from a Crome or Firefox browser extension instead of a web page?

Shanqing Cai

unread,
Aug 15, 2018, 12:42:28 PM8/15/18
to TensorFlow.js Discussion
Yep, as a matter of fact, people have written such extensions before. For exapmle, https://github.com/JK0N/tensorflow-image-recognition-chrome-extension

Nikhil Thorat

unread,
Aug 15, 2018, 12:43:08 PM8/15/18
to aogan...@gmail.com, TensorFlow.js Discussion
Yes, there shouldn't be any issue.

On Wed, Aug 15, 2018 at 12:41 PM Arman Oganesian <aogan...@gmail.com> wrote:
Can i run tfjs completely from a Crome or Firefox browser extension instead of a web page?

--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/tfjs/.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/b61777fe-0539-493b-a54e-8561192f550f%40tensorflow.org.

Arman Oganesian

unread,
Aug 16, 2018, 12:35:27 PM8/16/18
to TensorFlow.js Discussion
Thank you!


On Wednesday, August 15, 2018 at 12:41:15 PM UTC-4, Arman Oganesian wrote:

x x

unread,
Oct 14, 2018, 10:03:29 AM10/14/18
to TensorFlow.js Discussion, aogan...@gmail.com
Hi,

I also want to use tfjs within chrome extension. In my case I want to load already built keras model and run gpu accelerated inference on it. As I understand in orded to use gpu acceleration I need to depend on tensorflow/tfjs-node, but when I try to import this dependency using require('@tensorflow/tfjs-node'); I keep getting TypeError: util_1.promisify is not a function. Is it possible to use tfjs-node in chrome extension? I'm new to web development, so I apologize if this questions  seems silly. Previously I've used keras-js for that purpose, and it worked, but unfortunatelly It's not developed anymore. The aforemention error originates in a following block of code:

Object.defineProperty(exports, "__esModule", { value: true });
var tfc = require("@tensorflow/tfjs-core");
var fs = require("fs");
var path_1 = require("path");
var util_1 = require("util");
var stat = util_1.promisify(fs.stat);
var writeFile = util_1.promisify(fs.writeFile);
var readFile = util_1.promisify(fs.readFile);
var mkdir = util_1.promisify(fs.mkdir);
var io_utils_1 = require("./io_utils");

Any help would be greatly appreciated. 
BR

Daniel Smilkov

unread,
Oct 14, 2018, 11:02:35 AM10/14/18
to rychu.e...@gmail.com, TensorFlow.js Discussion, aogan...@gmail.com
Hi,

Chrome extensions run in the browser, whereas tfjs-node is designed to run in Node.js (server-side), so it's not possible to run tfjs-node in a browser extension. As for getting GPU-acceleration, you don't need to depend on tfjs-node. The regular tensorflow/tfjs package uses webgl and provides gpu acceleration also.

Daniel


x x

unread,
Oct 14, 2018, 12:39:42 PM10/14/18
to TensorFlow.js Discussion, rychu.e...@gmail.com, aogan...@gmail.com
Hi Daniel,

Ok, now it's clear for me. Thanks for helping me out.

Take care, and keep up the good work:)

Neha Soni

unread,
Sep 14, 2021, 3:42:01 AM9/14/21
to TensorFlow.js Discussion, x x, Arman Oganesian
Hi all,
I am also trying to make chrome extension using speech model. But I am not able to even load .tflite model into extension.
Uncaught (in promise) ReferenceError: tflite is not defined
Suggestion will be much appreciated. Thanks.

Pratyay Banerjee

unread,
Sep 14, 2021, 4:40:41 AM9/14/21
to TensorFlow.js Discussion, sonin...@gmail.com

Can you share screenshots of your code if possible? Although using TFlite for chrome extensions are something new that I'm hearing for now  🤔

Neha Soni

unread,
Sep 14, 2021, 5:11:13 AM9/14/21
to TensorFlow.js Discussion, putuban...@gmail.com, Neha Soni
Hi @Pratyay Banerjee

Sure. Here is the sample code of background.js --
/**
Function callled when extension installed into browser.
*/
chrome.runtime.onInstalled.addListener(function() {    
     // load TFLite model into browser
    async function load_tflite_model() {
        const tfliteModel = await tflite.loadTFLiteModel(
        );
        console.log("tfliteModel..",tfliteModel)
        alert('Sucessfully loaded model');
      }
    load_tflite_model();
});

Jason Mayes

unread,
Sep 14, 2021, 7:25:20 PM9/14/21
to TensorFlow.js Discussion, sonin...@gmail.com, x x, Arman Oganesian
Please note, we no longer support Google Groups as we now have the TF Forum to ask questions like this - please consider starting a thread there if still unresolved.

As FYI you may need to also check your chrome extension manifest.json file has correct permissions to load external scripts etc in else it will be blocked by default and you wont be able to use 3rd party JS in your extension at runtime. Here is an example I made that works for me:

{
  "manifest_version": 2,
  "name": "AppName",
  "description": "Blah",
  "version": "1",
  "permissions": [
    "activeTab",
    "declarativeContent",
    "webRequest",
    "webRequestBlocking",
    "<all_urls>",
    "storage",
    "tabs",
    "videoCapture",
    "audioCapture"
  ],
  "background": {
    "page": "background.html",
    "persistent": true
  },
  "browser_action": {
    "default_title": "TFJS Example"
  },
 "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["main.js"],
      "css": ["style.css"],
      "run_at": "document_start",
      "all_frames": true
    }
  ],  
  "content_security_policy": "script-src 'self' https://cdn.jsdelivr.net 'unsafe-eval'; object-src 'self'",
  "commands": {
    "_execute_browser_action": {
      "suggested_key": {
        "windows": "Ctrl+Shift+S",
        "mac": "Command+Shift+S",
        "chromeos": "Ctrl+Shift+S",
        "linux": "Ctrl+Shift+S"
      }
    }
  },
  "web_accessible_resources": [
    "yourscripts.js"
  ]

Jason Mayes

unread,
Sep 14, 2021, 7:26:10 PM9/14/21
to TensorFlow.js Discussion, Jason Mayes, sonin...@gmail.com, x x, Arman Oganesian
And PS for future discussion please consider migrating over to https://discuss.tensorflow.org/tag/tfjs - and tag your post with "TFJS" so our team finds it. Thank you!
Reply all
Reply to author
Forward
0 new messages