Skip to content

Commit

Permalink
fix: hold onto console.debug ref
Browse files Browse the repository at this point in the history
Code on https://streamedian.com/demo/free/ overwrites window.console
  • Loading branch information
samuelmaddock committed Jul 2, 2020
1 parent a012a9e commit 42d44f1
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/metastream-remote-extension/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@
// Code within function will be injected into main world.
// No closure variables are allowed within the function body.
const mainWorldScript = function() {
// Hold refs which could be overwritten
const debug = console.debug || console.log

// Injected by Metastream
console.debug(`Metastream main world script ${location.href}`)
debug(`Metastream main world script ${location.href}`)

// Hide opener when Metastream opens media in a popup.
// Prevents pages from redirecting app.getmetastream.com, but still allows
Expand Down Expand Up @@ -238,7 +241,7 @@
const { data: action } = event
if (typeof action !== 'object' || typeof action.type !== 'string') return

console.debug(`[Metastream Remote] Received player event`, action)
debug(`[Metastream Remote] Received player event`, action)

switch (action.type) {
case 'set-settings': {
Expand Down Expand Up @@ -336,7 +339,7 @@
}

set metadata(metadata) {
console.debug('MediaSession.metadata', metadata)
debug('MediaSession.metadata', metadata)
this._metadata = metadata
dispatchMediaEvent({
type: 'media-metadata-change',
Expand Down Expand Up @@ -366,15 +369,15 @@
if (typeof handler !== 'function' || handler.toString() === noopStr) {
return // ignore noop handlers (seen on tunein.com)
}
console.debug(`MediaSession.setActionHandler '${name}'`)
debug(`MediaSession.setActionHandler '${name}'`)
this._handlers[name] = handler
this.validateHandlers()
}

execActionHandler(name, ...args) {
if (!playerSettings.mediaSessionProxy) return false
if (this._handlers.hasOwnProperty(name)) {
console.debug(`MediaSession.execActionHandler '${name}'`, ...args)
debug(`MediaSession.execActionHandler '${name}'`, ...args)
this._handlers[name](...args)
return true
}
Expand All @@ -388,7 +391,7 @@
enumerable: false,
writable: true
})
console.debug('Overwrote navigator.mediaSession')
debug('Overwrote navigator.mediaSession')

//===========================================================================
// HTMLMediaPlayer class for active media element.
Expand Down Expand Up @@ -647,7 +650,7 @@

const ATTEMPT_INTERVAL = 200
const tryPlayback = () => {
console.debug(
debug(
`Attempting to force start playback [#${attempt++}][networkState=${
this.media.networkState
}][readyState=${this.media.readyState}]`
Expand Down Expand Up @@ -759,15 +762,15 @@
}

if (playButton instanceof HTMLButtonElement || playButton instanceof HTMLDivElement) {
console.debug('Attempting autoplay click', playButton)
debug('Attempting autoplay click', playButton)
playButton.click()
}
}

// Try different methods of initiating playback
const attemptAutoplay = () => {
if (hasActiveMedia()) return
console.debug(`Attempting autoplay in ${location.origin}`)
debug(`Attempting autoplay in ${location.origin}`)
if (playJwPlayer()) return
if (playVideoJS()) return
if (pressStart()) return
Expand Down Expand Up @@ -885,7 +888,7 @@
if (isFullscreen) stopAutoFullscreen()
isFullscreen = true

console.debug('Starting autofullscreen', target)
debug('Starting autofullscreen', target)

// Prevent scroll offset
if ('scrollRestoration' in history) {
Expand Down Expand Up @@ -916,7 +919,7 @@
}

function stopAutoFullscreen() {
console.debug('Stopping autofullscreen')
debug('Stopping autofullscreen')
isFullscreen = false
fullscreenElement = undefined
document.documentElement.minHeight = ''
Expand Down Expand Up @@ -1069,7 +1072,7 @@ ${ignoredSelectors}:empty {
if (player) player.destroy()
player = new HTMLMediaPlayer(media)

console.debug('Set active media', media, media.src, media.duration)
debug('Set active media', media, media.src, media.duration)
window.MEDIA = media

if (autoplayTimerId) {
Expand All @@ -1087,7 +1090,7 @@ ${ignoredSelectors}:empty {
const addMedia = media => {
if (mediaList.has(media) || mediaCooldownList.has(media)) return

console.debug('Add media', media, media.src, media.duration)
debug('Add media', media, media.src, media.duration)
mediaList.add(media)

// Immediately mute to prevent being really loud
Expand Down

0 comments on commit 42d44f1

Please sign in to comment.