Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Tweak ServiceDetectionUtility.ts to not fire for internal browser pages (#2287)

Leendert de Borst835ad0976a86
diff --git a/apps/browser-extension/src/utils/serviceDetection/ServiceDetectionUtility.ts b/apps/browser-extension/src/utils/serviceDetection/ServiceDetectionUtility.ts
index da8c03ac3..2c7868bfc 100644
--- a/apps/browser-extension/src/utils/serviceDetection/ServiceDetectionUtility.ts
+++ b/apps/browser-extension/src/utils/serviceDetection/ServiceDetectionUtility.ts
@@ -5,6 +5,20 @@ import { FormDetector } from '../formDetector/FormDetector';
* Shared between content script and popup dashboard
*/
export class ServiceDetectionUtility {
+ /**
+ * Check if a URL points to an actual website (http/https). Browser-internal pages such as
+ * new tab, settings and extension pages (chrome://, about:, edge://, moz-extension:// etc.)
+ * are not websites and should not be used for service detection.
+ */
+ public static isWebsiteUrl(rawUrl: string): boolean {
+ try {
+ const url = new URL(rawUrl);
+ return url.protocol === 'http:' || url.protocol === 'https:';
+ } catch {
+ return false;
+ }
+ }
+
/**
* Sanitize a raw URL down to its origin (scheme + host + port), stripping the
* path, query string and fragment.
@@ -48,6 +62,16 @@ export class ServiceDetectionUtility {
* Get service information from tab data (for use in popup dashboard)
*/
public static getServiceInfoFromTab(tabUrl: string, tabTitle?: string): ServiceInfo {
+ // Skip browser-internal pages (new tab, settings, extension pages) as they are not services.
+ if (!this.isWebsiteUrl(tabUrl)) {
+ return {
+ suggestedNames: [],
+ currentUrl: '',
+ serviceUrl: '',
+ domain: ''
+ };
+ }
+
try {
const url = new URL(tabUrl);
const location = {
diff --git a/apps/browser-extension/src/utils/serviceDetection/__tests__/ServiceDetectionUtility.test.ts b/apps/browser-extension/src/utils/serviceDetection/__tests__/ServiceDetectionUtility.test.ts
new file mode 100644
index 000000000..16593fcd4
--- /dev/null
+++ b/apps/browser-extension/src/utils/serviceDetection/__tests__/ServiceDetectionUtility.test.ts
@@ -0,0 +1,47 @@
+import { describe, it, expect } from 'vitest';
+
+import { ServiceDetectionUtility } from '../ServiceDetectionUtility';
+
+describe('ServiceDetectionUtility.isWebsiteUrl', () => {
+ it.each([
+ 'https://example.com',
+ 'http://localhost:3000/login',
+ ])('should accept %s', (url) => {
+ expect(ServiceDetectionUtility.isWebsiteUrl(url)).toBe(true);
+ });
+
+ it.each([
+ 'chrome://newtab/',
+ 'chrome://settings/passwords',
+ 'about:blank',
+ 'about:preferences',
+ 'edge://settings',
+ 'brave://settings',
+ 'moz-extension://abc123/popup.html',
+ 'chrome-extension://abc123/popup.html',
+ 'file:///Users/test/index.html',
+ '',
+ 'not a url',
+ ])('should reject %s', (url) => {
+ expect(ServiceDetectionUtility.isWebsiteUrl(url)).toBe(false);
+ });
+});
+
+describe('ServiceDetectionUtility.getServiceInfoFromTab', () => {
+ it('should detect service info for a regular website', () => {
+ const info = ServiceDetectionUtility.getServiceInfoFromTab('https://www.github.com/login', 'Sign in to GitHub');
+ expect(info.serviceUrl).toBe('https://www.github.com');
+ expect(info.domain).toBe('github.com');
+ expect(info.suggestedNames.length).toBeGreaterThan(0);
+ });
+
+ it('should return empty info for browser internal pages', () => {
+ const info = ServiceDetectionUtility.getServiceInfoFromTab('chrome://newtab/', 'New Tab');
+ expect(info).toEqual({
+ suggestedNames: [],
+ currentUrl: '',
+ serviceUrl: '',
+ domain: ''
+ });
+ });
+});