Skip to content
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

[Proposal] enable debug logs as soon as __RX_PLAYER_DEBUG_MODE__ is set #1626

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

peaBerberian
Copy link
Collaborator

@peaBerberian peaBerberian commented Jan 9, 2025

Today the RX_PLAYER_DEBUG_MODE__ global boolean only enable debug logs if it is set BEFORE the RxPlayer files are evaluated / initially executed.

This is difficult to explain to people not used to that kind of tricks.

In this commit, I propose to perform an ugly Object.defineProperty trick on the global scope (window / globalThis) so we enable debug mode even if the RxPlayer was already imported.

This way:

  1. any application running with the RxPlayer could just at any time set something like window.RX_PLAYER_DEBUG_MODE__ = true in the console to obtain debug logs

  2. RxPaired's client script could be included in the console at any time without asking users to pass as argument the RxPlayer class if it's done at runtime.

This can be seen as hacky and unusual, we would also mess ourselves with global scope which we usually don't like to do as a library.

However reserving the __RX_PLAYER_DEBUG_MODE__ global property and reacting on it still doesn't seems outlandish to me.


Note that executing two times the RxPlayer files will make only the last one react to that property. I think this is not an issue because applications should never execute two times the same RxPlayer file in a given JavaScript realm (if it does, they rely on a bundler or user-agent not respecting ECMAScript's specification regarding module evaluation, so it's OK IMO to not support that case).

Today the `RX_PLAYER_DEBUG_MODE__` global boolean only enable debug logs
if it is set **BEFORE** the RxPlayer files are evaluated / initially
  executed.

This is difficult to explain to people not used to that kind of tricks.

In this commit, I propose to perform an ugly `Object.defineProperty`
trick on the global scope (`window` / `globalThis`) so we enable debug
mode even if the RxPlayer was already imported.

This way:

  1. any application running with the RxPlayer could just at any time
     set something like `window.RX_PLAYER_DEBUG_MODE__ = true` in the
     console to obtain debug logs

  2. [RxPaired](https://github.com/canalplus/RxPaired/)'s client script
     could be included in the console at any time without asking users
     to pass as argument the RxPlayer class if it's done at runtime.

This can be seen as hacky and unusual, we would also mess ourselves
with global scope which we usually don't like to do as a library.

However reserving the `__RX_PLAYER_DEBUG_MODE__` global property and
reacting on it still doesn't seems outlandish to me.

---

Note that executing two times the RxPlayer files will make only the
last one react to that property. I think this is not an issue because
applications should never execute two times the same RxPlayer file in
a given JavaScript realm (if it does, they rely on a bundler or
user-agent not respecting ECMAScript's specification regarding
module evaluation, so it's OK IMO to not support that case).
@peaBerberian peaBerberian force-pushed the misc/listen-to-debug-mode branch from 17fb6af to fb3df48 Compare January 9, 2025 14:43
@peaBerberian peaBerberian changed the title [Proposal] enable debug logs as soon as __RX_PLAYER_DEBUG_MODE__ [Proposal] enable debug logs as soon as __RX_PLAYER_DEBUG_MODE__ is set Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant