Chrome extension

Skip to first unread message

Arman Oganesian

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

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,

Nikhil Thorat

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

On Wed, Aug 15, 2018 at 12:41 PM Arman Oganesian <> 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
Visit this group at
To view this discussion on the web visit

Arman Oganesian

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

Oct 14, 2018, 10:03:29 AM10/14/18
to TensorFlow.js Discussion,

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. 

Daniel Smilkov

Oct 14, 2018, 11:02:35 AM10/14/18
to, TensorFlow.js Discussion,

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.


x x

Oct 14, 2018, 12:39:42 PM10/14/18
to TensorFlow.js Discussion,,
Hi Daniel,

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

Take care, and keep up the good work:)

Neha Soni

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

Sep 14, 2021, 4:40:41 AM9/14/21
to TensorFlow.js Discussion,

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

Sep 14, 2021, 5:11:13 AM9/14/21
to TensorFlow.js Discussion,, 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(
        alert('Sucessfully loaded model');

Jason Mayes

Sep 14, 2021, 7:25:20 PM9/14/21
to TensorFlow.js Discussion,, 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": [
  "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' '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": [

Jason Mayes

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