Skip to content

Commit 4018c50

Browse files
authored
2.2 (#16)
* fix: youtube bypassCSP #15 * doc: 2.2 * doc: fix package stats * doc: add note
1 parent 92524f5 commit 4018c50

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ Check [Keep a Changelog](http://keepachangelog.com) for recommendations on how t
1717
- Shelljs vs Execa
1818
- Support for other sites
1919

20+
## [2.2.0] - September 2024
21+
- Youtube CSP bypass [#15](https://github.com/lanly-dev/VSCode-LMPTM/issues/15)
22+
- webpack 5.94.0 compiled successfully in 8730 ms
23+
- 20 files, 1.4MB, 1.93.0
24+
25+
### Note
26+
- Chrome team added the [Trusted Types to YouTube](https://developer.chrome.com/blog/trusted-types-on-youtube) - thanks [Matthew](https://github.com/mattzgg) for the info
27+
- There is probably a proper way to comply with the new security requirement but yeah, one shortcut is just to bypass it by disabling the [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)
28+
- It seems like the webpack (in old project/machine) that used to publish this extension doesn't combine files, another package stats:
29+
- webpack 5.94.0 compiled successfully in 3000 ms
30+
- 15 files, 1.4MB, 1.93.0
31+
2032
## [2.1.0] - July 2024
2133
- Fix Spotify and YouTube Music due to its UI change
2234
- webpack 5.92.1 compiled successfully in 10241 ms

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ This extension launches a Chrome/Chromium browser to the 4 popular music sites,
1818
Supports SoundCloud, Spotify, YouTube, and YouTube Music
1919

2020
## Requirements
21-
Required Chromium-based browser
21+
- Required Chromium-based browser
22+
- [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) is disabled for Spotify, Youtube, and Youtube Music
2223

2324
## Extension Settings
2425
* `lmptm.browserPath`: Specify custom browser executable file path.
@@ -33,6 +34,9 @@ Required Chromium-based browser
3334
- Won't be able to log into YouTube and SoundCloud(email method)
3435

3536
## Release Notes
37+
### 2.2.0
38+
- CSP bypass for Youtube and Youtube Music
39+
3640
### 2.1.0
3741
- Fix Spotify and YouTube Music for its UI changes
3842

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"displayName": "Let Me Play The Music",
44
"description": "Playback control buttons for the popular music sites",
55
"homepage": "https://github.com/lanly-dev/VSCode-LMPTM",
6-
"version": "2.1.0",
6+
"version": "2.2.0",
77
"publisher": "lanly-dev",
88
"engines": {
9-
"vscode": "^1.91.0"
9+
"vscode": "^1.93.0"
1010
},
1111
"extensionKind": [
1212
"ui"
@@ -72,7 +72,7 @@
7272
"type": "array",
7373
"default": [
7474
"https://soundcloud.com",
75-
"https://www.youtube.com",
75+
"https://www.youtube.com/trending",
7676
"https://open.spotify.com",
7777
"https://music.youtube.com"
7878
],
@@ -130,10 +130,10 @@
130130
"devDependencies": {
131131
"@types/copy-webpack-plugin": "^8.0.1",
132132
"@types/karma-chrome-launcher": "^3.1.4",
133-
"@types/node": "^20.14.10",
133+
"@types/node": "^22.5.5",
134134
"@types/puppeteer-core": "^5.4.0",
135135
"@types/shelljs": "^0.8.15",
136-
"@types/vscode": "^1.91.0",
136+
"@types/vscode": "^1.93.0",
137137
"@typescript-eslint/eslint-plugin": "^7.15.0",
138138
"@typescript-eslint/parser": "^7.15.0",
139139
"copy-webpack-plugin": "^12.0.2",
@@ -142,9 +142,9 @@
142142
"shelljs": "^0.8.5",
143143
"ts-loader": "^9.5.1",
144144
"ts-node": "^10.9.2",
145-
"typescript": "^5.5.3",
146-
"vsce": "^2.5.1",
147-
"webpack": "^5.92.1",
145+
"typescript": "^5.6.2",
146+
"vsce": "^2.15.0",
147+
"webpack": "^5.94.0",
148148
"webpack-cli": "^5.1.4"
149149
},
150150
"dependencies": {

src/browser.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class Browser {
6060
}
6161

6262
Browser.launched = true
63-
// console.log('###########################################')
63+
// console.log('#### Browser Launched ####')
6464
puppeteer.launch({
6565
args,
6666
defaultViewport: null,
@@ -301,10 +301,7 @@ export default class Browser {
301301
await page.waitForNetworkIdle() // this somehow prevents navigation error
302302
const pageURL = page.url()
303303
const brand = this.musicBrandCheck(pageURL)
304-
305-
// Spotify needs bypass CSP
306-
// won't stick to another site (if go to another URL) after set
307-
if (brand === 'spotify') this.spotifyBypassCSP(page)
304+
this.bypassCSP(brand, page)
308305

309306
const title = await page.title()
310307

@@ -339,9 +336,7 @@ export default class Browser {
339336
private async pageCreated(page: puppeteer.Page) {
340337
const pageURL = page.url()
341338
const brand = pageURL === 'about:blank' ? 'other' : this.musicBrandCheck(pageURL)
342-
343-
// Spotify needs bypass CSP
344-
if (brand === 'spotify') this.spotifyBypassCSP(page)
339+
this.bypassCSP(brand, page)
345340

346341
let title = pageURL === 'about:blank' ? pageURL : await page.title()
347342
if (title === '') title = 'New Tab'
@@ -422,7 +417,9 @@ export default class Browser {
422417
}
423418
}
424419

425-
private async spotifyBypassCSP(page: puppeteer.Page) {
420+
// Won't stick if go to another site (if go to another URL)
421+
private async bypassCSP(brand: string, page: puppeteer.Page) {
422+
if (['spotify', 'youtube', 'ytmusic'].includes(brand)) await page.setBypassCSP(true)
426423
page.setBypassCSP(true)
427424
// for debugging
428425
await page.evaluate(() => sessionStorage.setItem('bypassCSP', 'true'))

src/inject/script.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ function click() {
5252
if (href.includes('soundcloud.com')) {
5353
if (!document.querySelector('.m-visible')) {
5454
btnPick.disabled = true
55-
return void showInfo(btnPick, 'soundcloud')
55+
return void showRejectInfo(btnPick, 'soundcloud')
5656
}
5757
brand = 'soundcloud'
5858
} else if (href.includes('open.spotify.com')) {
5959
if (!navigator.mediaSession.metadata.title) {
6060
btnPick.disabled = true
61-
return void showInfo(btnPick, 'spotify')
61+
return void showRejectInfo(btnPick, 'spotify')
6262
}
6363
brand = 'spotify'
6464
} else if (href.includes('www.youtube.com')) {
6565
if (!href.includes('/watch')) {
6666
btnPick.disabled = true
67-
return void showInfo(btnPick, 'youtube')
67+
return void showRejectInfo(btnPick, 'youtube')
6868
}
6969
brand = 'youtube'
7070
} else if (href.includes('music.youtube.com')) {
7171
if (!href.includes('/watch')) {
7272
btnPick.disabled = true
73-
return void showInfo(btnPick, 'ytmusic')
73+
return void showRejectInfo(btnPick, 'ytmusic')
7474
}
7575
brand = 'ytmusic'
7676
} else {
@@ -164,7 +164,7 @@ function changeBtnAttr(brand) {
164164
btnPick.innerHTML = null
165165
}
166166

167-
function showInfo(btnPick, brand) {
167+
function showRejectInfo(btnPick, brand) {
168168
btnPick.className = `btn-pick-float border-gray ${brand}-info`
169169
let msg = 'Something is not right...'
170170
switch (brand) {

0 commit comments

Comments
 (0)