Coder Social home page Coder Social logo

Comments (12)

sentialx avatar sentialx commented on August 24, 2024 1

https://github.com/sentialx/electron-extensions/releases/tag/v3.0.0

from electron-extensions.

sentialx avatar sentialx commented on August 24, 2024 1

@Worie That's weird, because the audible property is being recomputed on each call. I will need to investigate it.

from electron-extensions.

Worie avatar Worie commented on August 24, 2024 1

Yes. Same thing happens. You can see this commit: Worie/electron-quick-start@66b8a88 and run it on master from this fork: https://github.com/Worie/electron-quick-start .

from electron-extensions.

sentialx avatar sentialx commented on August 24, 2024

Hi, there is a tab object in the sender parameter. So you may want to use sender.tab.audible.

from electron-extensions.

Worie avatar Worie commented on August 24, 2024

Thanks for fast reply! Missed that out. Unfortunately, audible property is missing in sender.tab.

{ 
   "active":false,
   "autoDiscardable":false,
   "discarded":false,
   "highlighted":false,
   "id":2,
   "incognito":false,
   "index":2,
   "pinned":false,
   "selected":false,
   "title":"localhost:9080",
   "url":"http://localhost:9080/",
   "windowId":2
}

I assume it's not implemented by electron nor electron-extensions then? Not sure if it's easy/possible to polyfill it somehow.

from electron-extensions.

Worie avatar Worie commented on August 24, 2024

nice! any plans for the release? :)

from electron-extensions.

Worie avatar Worie commented on August 24, 2024

You're always one step ahead :)

I'm just wondering - does this data that get's injected into tab object is generated once, say per page load - or is it recomputing those properties (for example audible) per each reference?

I'm asking, because the extension that I am working on (and it has been working on Chromium itself) does something like this:

  • Every N miliseconds, asks background script for audio playing in the tabs
  • Background scripts replies with the tabs that are currently playing
  • Content script gets this value injected into global scope via script tag, so it can be accessed on the client side.

Below the code, adjusted for Electron purposes.

manifest.json

{
  "manifest_version": 2,
  "name": "AudioDetector",
  "version": "0.1",
  "background": {
    "scripts": [
      // polyfill for promises
      "chrome-extension-async.js",
      "background.js"
    ]
  },
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": ["content.js"],
      "all_frames": true
    }
  ],
  "permissions": [
    "tabs",
    "http://*/",
    "https://*/"
  ]
}

content.js

const startDetection = () => {

  return new Promise(async (res, reject) => {
    var port = chrome.runtime.connect({ name: "requestAudioState" });

    setInterval(() => {
        port.postMessage({});
    }, 250);

    port.onMessage.addListener(function requestAudio(msg) {
      
      var elt = document.createElement("script");
      elt.innerHTML = `
        window.audioState = Boolean(${msg.playing});
      `;
      document.head.appendChild(elt);
      elt.remove();
    });
  });
};

startDetection();

background.js

chrome.runtime.onConnect.addListener(async function (port) {
  port.onMessage.addListener(async function handler(msg, obj) {
    port.postMessage({
      playing: obj.sender.tab.playing,
    });
  });
});

Visiting for example https://youtube.com/ should have window.audioState false when no audio is played, and window.audioState true when it does (that's the behavior working in Chromium).

Unfortunately, when I run this in electron using your package, it's always false - thus I'm wondering whether the value gets recomputed on each call. If I send whole tab object to the content script (stringified) - it's exactly same object. Have you perhaps tested it to check whether audible was true in some scenarios? Can't get that to work. Ty!

from electron-extensions.

sentialx avatar sentialx commented on August 24, 2024

@Worie Okay, I published 4.0.0 to npm. Also, please be aware of breaking changes: https://github.com/sentialx/electron-extensions/releases/tag/v4.0.0

from electron-extensions.

Worie avatar Worie commented on August 24, 2024

Hey hey! TY for amazing support :)

Unfortunately, I'm still having issues after migrating to 4.0.*.

When new import { ExtensibleSession } from 'electron-extensions/main'; is added to the project and I try to load extension with 👇

app.on('ready', () => {
  const extensions = new ExtensibleSession(session.defaultSession);
  extensions.loadExtension('/some-magic-path/audio-detector');

My electron app crashes and devtools get disconeccted (though my extension is not a devtools one) with such message:
image

Electron shows up with blank page. When I try to reload it, app seems loading - then devtools crash and the application goes blank.

This does not happen if I downgrade to 3.0.0 with import { ExtensibleSession } from 'electron-extensions'; - even though the audible property is not recomputed, surely.

Package version and import is the only thing that has changed

from electron-extensions.

sentialx avatar sentialx commented on August 24, 2024

Could you reproduce it using electron-quick-start?

from electron-extensions.

sentialx avatar sentialx commented on August 24, 2024

@Worie Okay, I published 4.0.2 with the fix.

from electron-extensions.

Worie avatar Worie commented on August 24, 2024

Nice! Now it's working like expected, ty! :)

from electron-extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.