Skip to content

Duck Player Native - Age restricted error not being caught #1829

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion injected/src/features/duck-player-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class DuckPlayerNativeFeature extends ContentFeature {

const locale = args?.locale || args?.language || 'en';
const env = new Environment({
debug: this.isDebug,
debug: this.isDebug || true,
injectName: import.meta.injectName,
platform: this.platform,
locale,
Expand Down
4 changes: 4 additions & 0 deletions injected/src/features/duckplayer-native/error-detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class ErrorDetection {
if (documentBody) {
// Check if iframe already contains error
if (checkForError(this.selectors.youtubeError, documentBody)) {
// @ts-expect-error ytcfg is not typed
console.log('Window Object', window, window.ytcfg);
const error = getErrorType(window, this.selectors.signInRequiredError, this.logger);
this.handleError(error);
return;
Expand Down Expand Up @@ -97,6 +99,8 @@ export class ErrorDetection {
mutation.addedNodes.forEach((node) => {
if (checkForError(this.selectors.youtubeError, node)) {
this.logger.log('A node with an error has been added to the document:', node);
// @ts-expect-error ytcfg is not typed
console.log('Window Object', window, window.ytcfg);
const error = getErrorType(window, this.selectors.signInRequiredError, this.logger);
this.handleError(error);
}
Expand Down
12 changes: 12 additions & 0 deletions injected/src/features/duckplayer-native/youtube-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export function getErrorType(windowObject, signInRequiredSelector, logger) {

if (!currentWindow.ytcfg) {
logger?.warn('ytcfg missing!');
setInterval(() => {
if (currentWindow.ytcfg) {
logger?.log('Got ytcfg', currentWindow.ytcfg);
} else {
logger?.warn('ytcfg still missing!');
console.log('window.client', currentWindow.clientInformation);
}
}, 300);
} else {
logger?.log('Got ytcfg', currentWindow.ytcfg);
}
Expand All @@ -72,16 +80,20 @@ export function getErrorType(windowObject, signInRequiredSelector, logger) {
previewPlayabilityStatus: { desktopLegacyAgeGateReason, status },
} = playerResponse;

console.log('playerResponse', playerResponse);
// 1. Check for UNPLAYABLE status
if (status === 'UNPLAYABLE') {
console.log('UNPLAYABLE');
// 1.1. Check for presence of desktopLegacyAgeGateReason
if (desktopLegacyAgeGateReason === 1) {
console.log('AGE RESTRICTED');
logger?.log('AGE RESTRICTED ERROR');
return YOUTUBE_ERRORS.ageRestricted;
}

// 1.2. Fall back to embed not allowed error
logger?.log('NO EMBED ERROR');
console.log('NO EMBED');
return YOUTUBE_ERRORS.noEmbed;
}
}
Expand Down
Loading