Fix iframe detection

This commit is contained in:
Tamius Han 2025-06-17 22:48:34 +02:00
parent 178bb65b4a
commit 2bc95af73c
7 changed files with 79 additions and 40 deletions

View File

@ -86,7 +86,7 @@
:settings="settings" :settings="settings"
:eventBus="eventBus" :eventBus="eventBus"
:siteSettings="siteSettings" :siteSettings="siteSettings"
:frames="activeFrames" :hosts="activeHosts"
></PopupVideoSettings> ></PopupVideoSettings>
<BaseExtensionSettings <BaseExtensionSettings
v-if="selectedTab === 'extensionSettings'" v-if="selectedTab === 'extensionSettings'"
@ -94,7 +94,7 @@
:eventBus="eventBus" :eventBus="eventBus"
:siteSettings="siteSettings" :siteSettings="siteSettings"
:site="site.host" :site="site.host"
:frames="activeFrames" :hosts="activeHosts"
> >
</BaseExtensionSettings> </BaseExtensionSettings>
<ChangelogPanel <ChangelogPanel
@ -193,6 +193,8 @@ export default {
{ {
source: this, source: this,
function: (config, context) => { function: (config, context) => {
console.log('set-current-site | this.site:', this.site, 'config.site:', config.site);
if (this.site) { if (this.site) {
if (!this.site.host) { if (!this.site.host) {
// dunno why this fix is needed, but sometimes it is // dunno why this fix is needed, but sometimes it is
@ -209,7 +211,8 @@ export default {
} }
}); });
this.loadFrames(this.site); this.loadHostnames();
this.loadFrames();
} }
}, },
); );
@ -276,11 +279,6 @@ export default {
try { try {
this.logger.log('info','popup', '[popup::getSite] Requesting current site ...') this.logger.log('info','popup', '[popup::getSite] Requesting current site ...')
// CSM.port.postMessage({command: 'get-current-site'}); // CSM.port.postMessage({command: 'get-current-site'});
this.eventBus.send(
'probe-video',
{},
{ comms: {forwardTo: 'active'} }
);
this.eventBus.send( this.eventBus.send(
'get-current-site', 'get-current-site',
{}, {},
@ -301,13 +299,15 @@ export default {
isDefaultFrame(frameId) { isDefaultFrame(frameId) {
return frameId === '__playing' || frameId === '__all'; return frameId === '__playing' || frameId === '__all';
}, },
loadHostnames() {
this.activeHosts = this.site.hostnames;
},
loadFrames() { loadFrames() {
this.activeFrames = [{ this.activeFrames = [{
host: this.site.host, host: this.site.host,
isIFrame: false, // not used tho. Maybe one day isIFrame: false, // not used tho. Maybe one day
}]; }];
for (const frame in this.site.frames) { for (const frame in this.site.frames) {
if (!this.activeFrames.find(x => x.host === this.site.frames[frame].host)) { if (!this.activeFrames.find(x => x.host === this.site.frames[frame].host)) {
this.activeFrames.push({ this.activeFrames.push({

View File

@ -13,12 +13,12 @@
<small>{{ site }}</small> <small>{{ site }}</small>
</div> </div>
<div <div
v-if="frames" v-if="hosts"
class="tab" class="tab"
:class="{'active': tab === 'embeddedSites'}" :class="{'active': tab === 'embeddedSites'}"
@click="setTab(tab = 'embeddedSites')" @click="setTab(tab = 'embeddedSites')"
> >
Embedded content ({{frames?.length}} {{frames?.length === 1 ? 'site' : 'sites'}}) Embedded content ({{hosts?.length}} {{hosts?.length === 1 ? 'site' : 'sites'}})
</div> </div>
<div <div
class="tab" class="tab"
@ -38,10 +38,10 @@
></SiteExtensionSettings> ></SiteExtensionSettings>
</template> </template>
<template v-if="frames && tab === 'embeddedSites' && globalSettings"> <template v-if="hosts && tab === 'embeddedSites' && globalSettings">
<FrameSiteSettings <FrameSiteSettings
v-if="settings" v-if="settings"
:frames="frames" :hosts="hosts"
:settings="settings" :settings="settings"
></FrameSiteSettings> ></FrameSiteSettings>
</template> </template>
@ -178,7 +178,7 @@ export default {
'settings', 'settings',
'site', 'site',
'enableSettingsEditor', 'enableSettingsEditor',
'frames', 'hosts',
], ],
data() { data() {
return { return {

View File

@ -9,9 +9,9 @@
</div> </div>
</div> </div>
</div> </div>
<div v-for="frame of frames" :key="frame.host" @click="selectedSite = frame.host" class="flex flex-col container pointer hoverable" style="margin-top: 4px; padding: 0.5rem 1rem;"> <div v-for="host of hosts" :key="host" @click="selectedSite = host" class="flex flex-col container pointer hoverable" style="margin-top: 4px; padding: 0.5rem 1rem;">
<SiteListItem <SiteListItem
:frame="frame" :host="host"
:settings="settings" :settings="settings"
></SiteListItem> ></SiteListItem>
</div> </div>
@ -48,7 +48,7 @@ export default {
}, },
props: [ props: [
'settings', 'settings',
'frames', 'hosts',
], ],
data() { data() {
return { return {

View File

@ -2,9 +2,9 @@
<div> <div>
<div class="flex flex-row"> <div class="flex flex-row">
<div class="flex-grow pointer"> <div class="flex-grow pointer">
<b>{{ frame.host ?? frame.key }}</b> <b>{{ host }}</b>
<span :style="getSiteTypeColor(frame.type)"> <span :style="getSiteTypeColor(siteSettings?.data?.type)">
(config: {{frame.type ?? 'unknown'}}) (config: {{siteSettings?.data?.type ?? 'unknown'}})
</span> </span>
</div> </div>
<div>Edit</div> <div>Edit</div>
@ -15,10 +15,10 @@
</div> </div>
<div class="flex flex-row"> <div class="flex flex-row">
<small> <small>
Enabled: <span :style="getSiteEnabledColor(frame.host, 'enable')"><small>{{ getSiteEnabledModes(frame.host, 'enable') }}</small></span>;&nbsp; Enabled: <span :style="getSiteEnabledColor(host, 'enable')"><small>{{ getSiteEnabledModes(host, 'enable') }}</small></span>;&nbsp;
Aard <span :style="getSiteEnabledColor(frame.host, 'enableAard')"><small>{{ getSiteEnabledModes(frame.host, 'enableAard') }}</small></span>;&nbsp; Aard <span :style="getSiteEnabledColor(host, 'enableAard')"><small>{{ getSiteEnabledModes(host, 'enableAard') }}</small></span>;&nbsp;
kbd: <span :style="getSiteEnabledColor(frame.host, 'enableKeyboard')"><small>{{ getSiteEnabledModes(frame.host, 'enableKeyboard') }}</small></span> kbd: <span :style="getSiteEnabledColor(host, 'enableKeyboard')"><small>{{ getSiteEnabledModes(host, 'enableKeyboard') }}</small></span>
UI: <span :style="getSiteEnabledColor(frame.host, 'enableUI')"><small>{{ getSiteEnabledModes(frame.host, 'enableUI') }}</small></span> UI: <span :style="getSiteEnabledColor(host, 'enableUI')"><small>{{ getSiteEnabledModes(host, 'enableUI') }}</small></span>
</small> </small>
</div> </div>
</div> </div>
@ -29,15 +29,16 @@ import ExtensionMode from '../../../../../common/enums/ExtensionMode.enum';
export default { export default {
data() { data() {
return { return {
siteSettings: undefined siteSettings: undefined,
supportType: undefined
} }
}, },
props: [ props: [
'settings', 'settings',
'frame', 'host',
], ],
created() { created() {
this.siteSettings = this.settings.getSiteSettings(this.frame.host ?? this.frame.key); this.siteSettings = this.settings.getSiteSettings(this.host);
}, },
methods: { methods: {
getSiteTypeColor(siteType) { getSiteTypeColor(siteType) {

View File

@ -1,11 +1,10 @@
<template> <template>
<div class="flex flex-col relative h-full" style="padding-bottom: 20px"> <div class="flex flex-col relative h-full" style="padding-bottom: 20px">
<!-- <!--
Extension is disabled for a given site when it's disabled in full screen, since Extension is disabled for a given site when it's disabled in full screen, since
current settings do not allow the extension to only be disabled while in full screen current settings do not allow the extension to only be disabled while in full screen
--> -->
<template v-if="siteSettings.isEnabledForEnvironment(false, true) === ExtensionMode.Disabled && !enabledFrames?.length"> <template v-if="siteSettings.isEnabledForEnvironment(false, true) === ExtensionMode.Disabled && !enabledHosts?.length">
<div class="h-full flex flex-col items-center justify-center"> <div class="h-full flex flex-col items-center justify-center">
<div class="info"> <div class="info">
Extension is not enabled for this site. Extension is not enabled for this site.
@ -23,7 +22,7 @@
<b>Extension is disabled for this site.</b><br /> <b>Extension is disabled for this site.</b><br />
<small>Controls will only work on content embedded from the following sites:</small><br/> <small>Controls will only work on content embedded from the following sites:</small><br/>
<div class="w-full flex flex-row justify-center"> <div class="w-full flex flex-row justify-center">
<span v-for="frameSite of enabledFrames" :key="frameSite.host" class="website-name">{{frameSite.host}}</span> <span v-for="frameSite of enabledHosts" :key="frameSite.host" class="website-name">{{frameSite.host}}</span>
</div> </div>
</div> </div>
@ -118,17 +117,17 @@ export default {
'settings', 'settings',
'siteSettings', 'siteSettings',
'eventBus', 'eventBus',
'frames' 'hosts'
], ],
data() { data() {
return { return {
exec: null, exec: null,
ExtensionMode: ExtensionMode, ExtensionMode: ExtensionMode,
enabledFrames: [], enabledHosts: [],
}; };
}, },
watch: { watch: {
frames(val) { hosts(val) {
this.filterActiveSites(val); this.filterActiveSites(val);
} }
}, },
@ -140,6 +139,7 @@ export default {
function: (config) => this.handleConfigBroadcast(config) function: (config) => this.handleConfigBroadcast(config)
} }
); );
this.filterActiveSites(this.hosts);
}, },
mounted() { mounted() {
this.eventBus.sendToTunnel('get-ar'); this.eventBus.sendToTunnel('get-ar');
@ -149,13 +149,13 @@ export default {
}, },
methods: { methods: {
filterActiveSites(val) { filterActiveSites(val) {
this.enabledFrames = []; this.enabledHosts = [];
for (const site of val) { for (const host of val) {
const siteSettings = new SiteSettings(this.settings, site.host); const siteSettings = new SiteSettings(this.settings, host);
if (siteSettings.isEnabledForEnvironment(false, true) === ExtensionMode.Enabled) { if (siteSettings.isEnabledForEnvironment(false, true) === ExtensionMode.Enabled) {
this.enabledFrames.push(site); this.enabledHosts.push(host);
} }
} }
} }

View File

@ -93,12 +93,16 @@ export default class UWServer {
} }
} }
async _promisifyTabsGet(browserObj, tabId){ async _promisifyTabsGet(browserObj, tabId){
return new Promise( (resolve, reject) => { return new Promise( (resolve, reject) => {
browserObj.tabs.get(tabId, (tab) => resolve(tab)); browserObj.tabs.get(tabId, (tab) => resolve(tab));
}); });
} }
//#region CSS managemeent
async injectCss(css, sender) { async injectCss(css, sender) {
if (!css) { if (!css) {
return; return;
@ -167,6 +171,7 @@ export default class UWServer {
this.injectCss(newCss, sender); this.injectCss(newCss, sender);
} }
} }
//#endregion
extractHostname(url){ extractHostname(url){
var hostname; var hostname;
@ -214,7 +219,6 @@ export default class UWServer {
} }
//TODO: change extension icon based on whether there's any videos on current page //TODO: change extension icon based on whether there's any videos on current page
} }
registerVideo(sender) { registerVideo(sender) {
@ -288,7 +292,6 @@ export default class UWServer {
const tabHostname = await this.getCurrentTabHostname(); const tabHostname = await this.getCurrentTabHostname();
this.logger.info('getCurrentSite', 'Returning data:', {site, tabHostname}); this.logger.info('getCurrentSite', 'Returning data:', {site, tabHostname});
this.eventBus.send( this.eventBus.send(
'set-current-site', 'set-current-site',
{ {
@ -318,9 +321,12 @@ export default class UWServer {
return { return {
host: 'INVALID SITE', host: 'INVALID SITE',
frames: [], frames: [],
hostnames: [],
} }
} }
const hostnames = await this.comms.listUniqueFrameHosts();
if (this.videoTabs[ctab.id]) { if (this.videoTabs[ctab.id]) {
// if video is older than PageInfo's video rescan period (+ 4000ms of grace), // if video is older than PageInfo's video rescan period (+ 4000ms of grace),
// we clean it up from videoTabs[tabId].frames array. // we clean it up from videoTabs[tabId].frames array.
@ -343,6 +349,7 @@ export default class UWServer {
return { return {
...this.videoTabs[ctab.id], ...this.videoTabs[ctab.id],
host: this.extractHostname(ctab.url), host: this.extractHostname(ctab.url),
hostnames,
selected: this.selectedSubitem selected: this.selectedSubitem
}; };
} }
@ -352,7 +359,8 @@ export default class UWServer {
return { return {
host: this.extractHostname(ctab.url), host: this.extractHostname(ctab.url),
frames: [], frames: [],
selected: this.selectedSubitem hostnames,
selected: this.selectedSubitem,
} }
} }

View File

@ -122,6 +122,36 @@ class CommsServer {
//#endregion //#endregion
/**
* Lists all unique hosts that are present in all the frames of a given tab.
* This includes both hostname of the tab, as well as of all iframes embedded in it.
* @returns
*/
async listUniqueFrameHosts() {
const aTab = await this.activeTab;
const tabPort = this.ports[aTab.id];
const hosts = [];
for (const frame in tabPort) {
for (const portName in tabPort[frame]) {
const port = tabPort[frame][portName];
const host = port.sender.origin.split('://')[1];
// if host is invalid or already exists in our list, skip adding it
if (!host || hosts.includes(host)) {
continue;
}
hosts.push(host);
}
}
console.log('uniq hosts:', hosts)
return hosts;
}
sendMessage(message, context?) { sendMessage(message, context?) {
this.logger.debug('sendMessage', `preparing to send message ${message.command ?? ''} ...`, {message, context}); this.logger.debug('sendMessage', `preparing to send message ${message.command ?? ''} ...`, {message, context});
// stop messages from returning where they came from, and prevent // stop messages from returning where they came from, and prevent