Skip to content

Commit 85aad6a

Browse files
committed
fix: Resolved issue in which Chrome refused to load full extension in production mode because of certain angular features.
1 parent 471b54b commit 85aad6a

File tree

2 files changed

+31
-53
lines changed

2 files changed

+31
-53
lines changed

src/app/app.component.ts

+26-44
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,10 @@ import {DomSanitizer} from "@angular/platform-browser";
2525
template: `
2626
<div class="kc-extension-popup">
2727
<app-card [ks]="ks"
28-
(onImport)="import($event)"
2928
[loading]="sending"
3029
[disabled]="kcUnavailable"
3130
></app-card>
3231
</div>
33-
34-
<!-- <p-card>-->
35-
<!-- <ng-template pTemplate="header">-->
36-
<!-- <div class="flex flex-row align-items-center justify-content-center">-->
37-
<!-- <input [(ngModel)]="packet.metadata.title"-->
38-
<!-- pInputText-->
39-
<!-- class="p-fluid w-full">-->
40-
<!-- </div>-->
41-
<!-- </ng-template>-->
42-
43-
44-
<!-- <div class="p-grid kc-extension-popup">-->
45-
<!-- <div class="col-12" *ngIf="packet?.selectedText">-->
46-
<!-- <p-checkbox [(ngModel)]="includeHighlightedText" class="mb-4" [binary]="true" label="Include Highlighted Text"></p-checkbox>-->
47-
<!-- <textarea class="w-full" id="selectedText" [disabled]="!includeHighlightedText" rows="5" [(ngModel)]="packet.selectedText"></textarea>-->
48-
<!-- </div>-->
49-
50-
<!-- TODO: Eventually provide the ability to select a project directly from the extension-->
51-
52-
<!-- <div *ngIf="kcUnavailable" class="col-12">-->
53-
<!-- <div class="flex justify-content-center align-items-center text-red-500">-->
54-
<!-- Knowledge Canvas Unavailable<br>-->
55-
<!-- Make sure "Browser Extensions" is enabled in the Import Settings menu-->
56-
<!-- </div>-->
57-
<!-- </div>-->
58-
59-
<!-- <div class="col-12 flex justify-content-center align-items-center">-->
60-
<!-- <button pButton-->
61-
<!-- icon="pi pi-plus"-->
62-
<!-- class="w-full p-fluid shadow-5"-->
63-
<!-- [disabled]="kcUnavailable"-->
64-
<!-- [loading]="sending"-->
65-
<!-- pTooltip="Import"-->
66-
<!-- tooltipPosition="top"-->
67-
<!-- (click)="import($event)"></button>-->
68-
<!-- </div>-->
69-
7032
`,
7133
styles: [
7234
`
@@ -117,7 +79,7 @@ export class AppComponent {
11779
console.log('Got Chrome Tab: ', tab);
11880

11981
this.ks = {
120-
thumbnail: '',
82+
thumbnail: undefined,
12183
title: tab.title,
12284
description: '',
12385
accessLink: tab.url,
@@ -151,19 +113,39 @@ export class AppComponent {
151113
for (let m of tab.metadata.meta) {
152114
if (m.key == 'og:image') {
153115
this.ks.thumbnail = m.value ?? m.property ?? '';
154-
} else if (m.key == 'og:description') {
116+
fetch(this.ks.thumbnail).then((response) => {
117+
response.blob().then((iconBlob) => {
118+
let objectURL = URL.createObjectURL(iconBlob);
119+
let thumbnail = this.sanitizer.bypassSecurityTrustUrl(objectURL);
120+
console.log(`Got ks thumbnail: ${thumbnail} from iconURL: ${tab.favIconUrl}`);
121+
this.ks.thumbnail = thumbnail;
122+
})
123+
}).catch((reason) => {
124+
console.log('Failed to fetch thumbnail because: ', reason);
125+
})
126+
} else if (m.key == 'og:description' || m.key == 'description') {
155127
this.ks.description = m.value ?? m.property ?? '';
156-
}
157-
158-
if (m.key == 'keywords') {
128+
} else if (m.key == 'keywords') {
159129
this.ks.topics = m.value?.split(',');
160130
}
161131
}
162132
}
163133
})
134+
135+
setTimeout(() => {
136+
/*
137+
* NOTE: Cannot use (click) listener in HTML elements due to an issue with Chrome
138+
* See: https://stackoverflow.com/questions/70353636/angular-gives-refused-to-execute-inline-event-handler-error
139+
* See: https://stackoverflow.com/questions/36324333/refused-to-execute-inline-event-handler-because-it-violates-csp-sandbox
140+
*/
141+
// @ts-ignore
142+
document.getElementById('importBtn').addEventListener('click', () => {
143+
this.import()
144+
});
145+
}, 1000);
164146
}
165147

166-
async import($event: any) {
148+
import() {
167149
this.sending = true;
168150

169151
// Remove selected text if the user does not want it included

src/app/knowledge-source/card.component.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
16+
import {Component, Input, OnInit} from '@angular/core';
1717
import {KnowledgeSource} from "../models/knowledge.source.model";
1818

1919
@Component({
@@ -64,13 +64,14 @@ import {KnowledgeSource} from "../models/knowledge.source.model";
6464
6565
<ng-template pTemplate="footer">
6666
<button pButton
67+
id="importBtn"
6768
icon="pi pi-plus"
6869
class="w-full p-fluid shadow-5"
6970
[disabled]="disabled"
7071
[loading]="loading"
7172
pTooltip="Import"
72-
tooltipPosition="top"
73-
(click)="import($event)"></button>
73+
tooltipPosition="top">
74+
</button>
7475
</ng-template>
7576
</p-card>
7677
</div>
@@ -81,21 +82,16 @@ import {KnowledgeSource} from "../models/knowledge.source.model";
8182
export class CardComponent implements OnInit {
8283
@Input() ks: Partial<KnowledgeSource> = {};
8384

84-
@Output() onImport = new EventEmitter();
85-
8685
@Input() disabled: boolean = false;
8786

8887
@Input() loading: boolean = false;
8988

9089
includeHighlightedText: boolean = true;
9190

9291
constructor() {
93-
}
9492

95-
ngOnInit(): void {
9693
}
9794

98-
import(_: MouseEvent) {
99-
this.onImport.emit()
95+
ngOnInit(): void {
10096
}
10197
}

0 commit comments

Comments
 (0)