DEV Community

Carl
Carl

Posted on

"broadcast" a window from an electron app to my local network?

Hello friends! So I have made this super simple electron app in javascript, added the code below. This app opens up a window that displays youtube TV with an ad blocker, and spoofs the user agent so that youtube thinks that you are a TV, so it doesn't redirect you to normal youtube. Simple stuff. Now, I have a smart TV that I can install web-applications on. So I am trying to somehow use the electron app as a server that "broadcasts" an instance of the "mainWindow" on my local network, so that I can use this electron app on my TV even tough it is hosted and running on my PC. I've tried multiple different ways with express, webpack, etc etc but no matter what I cannot seem to make it work. Electron is obviously not the best choice for a server-like application, but I need to use it since it has chromium integration which is required for the adblocker.

Does anyone have any idea of how I could make this work? Or am I just dreaming of doing something impossible? :)

const { ElectronBlocker } = require('@cliqz/adblocker-electron')
const fetch = require('cross-fetch')
const { app, BrowserWindow, session } = require('electron')
const SMART_TV_UA = 'Mozilla/5.0 (Linux; Tizen 2.3)';
const filter = {
urls: ['*://*.youtube.com/*']
}
app.on('ready', () => {
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
blocker.enableBlockingInSession(session.defaultSession);
});
session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
details.requestHeaders['User-Agent'] = SMART_TV_UA;
callback({ requestHeaders: details.requestHeaders })
});
const mainWindow = new BrowserWindow({width: 1920, height: 1080, frame: false, autoHideMenuBar: true});
mainWindow.loadURL('https://www.youtube.com/tv')
});
app.allowRendererProcessReuse = true;
app.userAgentFallback = SMART_TV_UA;

Top comments (0)