• Robert Knight's avatar
    Fix client failing to load on pages that define `self` · 362b4edf
    Robert Knight authored
    Fix client failing to load on pages that define `self` to be something
    other than `window`.
    
    When AnnotatorJS is bundled by browserify, it is first processed by
    browserify-shim* which adds references to a variable called 'global',
    which exists in Node but not the browser. Browserify then processes the
    result and assigns `global` to the value of the first variable from
    ['global', 'self', 'window'] which is already defined.
    
    https://github.com/hypothesis/h/pull/3385 fixed the problem when the
    page defines a variable called 'global' that is not an alias for
    'window' by reducing this list to ['self', 'window']. This still leaves
    pages that define 'self'.
    
    This commit fixes the problem by always making `global` (within CommonJS
    modules) always be assigned the value of `window`.
    
    * browserify-shim deals with the fact that AnnotatorJS 1.2.x is not a
    CommonJS module and exports its entry point as `window.Annotator`.
    362b4edf
create-bundle.js 6.1 KB