mobtimeapp / mobtime

A real-time, collaborative mob programming timer. Made with technology from the future, today!
https://mobti.me
MIT License
67 stars 38 forks source link

Fix for chromium-based browsers #246

Closed JStruk closed 2 years ago

JStruk commented 2 years ago

@mrozbarry This was the solution we came up with during the growth session to debug this, and seemed to allow the timer page to load and work again in the plugin. If there might be a better way to solve this, let's set up another growth session to explore it 😄

Problem:

The intelliJ mobtime plugin uses the chromium embedded framework under the hood (through JBCef), and it seems that window.Notification is not supported by chromium browsers (assumption from here: https://developer.mozilla.org/en-US/docs/Web/API/notification), but we are trying to access a permission property from window.Notification, this causes the plugin to show a blank screen when mobtime errors out: Screen Shot 2022-01-26 at 11 56 53 AM

Mobtime source: In timer.js, the externals object is defined:

app({
  init: actions.Init(null, {
    timerId: initialTimerId,
    externals: {
      documentElement: window.document,
      Notification: window.Notification, // window.Notification does not seem to be defined for chromium-based browsers
      storage: window.localStorage,
      location: window.location,
      history: window.history,
    },
    dark: 'dark' in flags,
  })

and in public/actions.js, we try assessing externals.Notification.permission:

allowNotification: externals.Notification.permission === 'granted',

and

state.externals.Notification.permission === 'granted'

Solution:

Check that externals.Notification is defined before accessing the permission property:

allowNotification:
      externals.Notification && externals.Notification.permission === 'granted',

and

state.externals.Notification &&
    state.externals.Notification.permission === 'granted'