Repository navigation
fix(extension): m1 disclosure drift and tiktok product paths #1602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,9 @@ | |
| "https://shopee.vn/*", | ||
| "https://*.lazada.vn/*", | ||
| "https://tiki.vn/*", | ||
| "https://www.tiktok.com/*", | ||
| "https://www.tiktok.com/view/product/*", | ||
| "https://www.tiktok.com/@*/product/*", | ||
| "https://www.tiktok.com/shop/*pdp/*", | ||
| "https://shop.tiktok.com/*", | ||
| "https://cellphones.com.vn/*", | ||
| "https://*.thegioididong.com/*", | ||
|
|
@@ -56,6 +58,7 @@ | |
| "https://didongviet.vn/*", | ||
| "https://phongvu.vn/*" | ||
| ], | ||
| "exclude_matches": ["https://www.tiktok.com/@*/video/*"], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Product pages with Chrome matches The current patterns cannot keep this product page while excluding video pages whose query contains Add a regression case for a product URL with
|
||
| "js": ["content/content-script.js"], | ||
| "run_at": "document_idle" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -485,7 +485,10 @@ async function runTests() { | |
| ) as { | ||
| permissions?: string[]; | ||
| host_permissions?: string[]; | ||
| content_scripts?: Array<{ matches?: string[] }>; | ||
| content_scripts?: Array<{ | ||
| matches?: string[]; | ||
| exclude_matches?: string[]; | ||
| }>; | ||
| }; | ||
| assert.deepEqual( | ||
| manifestJson.permissions, | ||
|
|
@@ -499,22 +502,31 @@ async function runTests() { | |
| for (const pattern of [...hosts, ...matches]) { | ||
| assert.ok(!pattern.includes('*.tiktok.com'), pattern); | ||
| } | ||
| const matchesPattern = (pattern: string, url: string) => | ||
| new RegExp( | ||
| // Chrome matches a pattern's path against the URL's path and query, | ||
| // never its fragment. | ||
| const matchesPattern = (pattern: string, url: string) => { | ||
| const u = new URL(url); | ||
| return new RegExp( | ||
| `^${pattern | ||
| .replace(/[.+?^${}()|[\]\\]/g, '\\$&') | ||
| .replace('://*\\.', '://(?:[^/]+\\.)?') | ||
| .replace(/\*/g, '.*')}$` | ||
| ).test(url); | ||
| ).test(`${u.origin}${u.pathname}${u.search}`); | ||
| }; | ||
| const excludes = manifestJson.content_scripts?.[0]?.exclude_matches ?? []; | ||
| const injectedOn = (url: string) => | ||
| matches.some((p) => matchesPattern(p, url)) && | ||
| !excludes.some((p) => matchesPattern(p, url)); | ||
| for (const url of [ | ||
| 'https://www.tiktok.com/@appleflagship/product/1729384756', | ||
| 'https://www.tiktok.com/view/product/1729384756', | ||
| 'https://www.tiktok.com/shop/pdp/iphone-16/1729384756', | ||
| 'https://www.tiktok.com/shop/vn/pdp/iphone-16/1729384756?src=x', | ||
| 'https://shop.tiktok.com/view/product/1729401928401', | ||
| ]) { | ||
| assert.ok( | ||
| matches.some((p) => matchesPattern(p, url)), | ||
| `content script must run on ${url}` | ||
| ); | ||
| assert.ok(injectedOn(url), `content script must run on ${url}`); | ||
| // ...and the extractor reads these as products, so the two agree. | ||
| assert.ok(extractIdsFromUrl('tiktok', url).externalItemId, url); | ||
| assert.ok( | ||
| hosts.some((p) => matchesPattern(p, url)), | ||
| url | ||
|
|
@@ -539,8 +551,23 @@ async function runTests() { | |
| [...(manifestJson.permissions ?? []), ...hosts].sort(), | ||
| 'CHROMEWEBSTORE.md permission table must match manifest.json' | ||
| ); | ||
| // On www.tiktok.com the content script runs only on product pages, not | ||
| // on the video feed (DOS/Rate#1601); host permissions are per origin. | ||
| for (const url of [ | ||
| 'https://www.tiktok.com/', | ||
| 'https://www.tiktok.com/foryou', | ||
| 'https://www.tiktok.com/@appleflagship/video/7291234567890', | ||
| 'https://www.tiktok.com/search?q=iphone', | ||
| 'https://www.tiktok.com/@appleflagship', | ||
| 'https://www.tiktok.com/@appleflagship/video/7291234567890?ref=/product/1', | ||
| 'https://www.tiktok.com/foryou#/view/product/1', | ||
| ]) { | ||
| assert.ok(!injectedOn(url), `content script must not run on ${url}`); | ||
|
Comment on lines
+556
to
+565
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Limit the TikTok content-script scope to the URL pathname. The The negative URL list in The scope check must ignore the query string. A broad
|
||
| } | ||
| const originOf = (pattern: string) => | ||
| pattern.replace(/^(https:\/\/[^/]+)\/.*$/, '$1/*'); | ||
| assert.deepEqual( | ||
| [...matches].sort(), | ||
| [...new Set(matches.map(originOf))].sort(), | ||
| hosts.filter((h) => !/rate\.vn/.test(h)).sort() | ||
| ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: DOS/Rate
Length of output: 4532
Script executed:
Repository: DOS/Rate
Length of output: 13370
Script executed:
Repository: DOS/Rate
Length of output: 10044
Script executed:
Repository: DOS/Rate
Length of output: 3160
Script executed:
Repository: DOS/Rate
Length of output: 1374
Script executed:
Repository: DOS/Rate
Length of output: 2900
Correct the TikTok scope sentence in the store changelog.
The manifest injects the content script on every
shop.tiktok.compage, because its match has no path restriction. The script runs on those pages and sends nothing on non-product pages. The changelog says the extension runs only on product pages, which is inaccurate forshop.tiktok.com. State the behavior separately for each host.Suggested fix
Committable suggestion