diff --git a/manifest.json b/manifest.json index adeaffca..b1c6bab4 100644 --- a/manifest.json +++ b/manifest.json @@ -83,6 +83,7 @@ "content_scripts": [ { + "run_at": "document_start", "matches": [ "https://steamdb.info/*" diff --git a/scripts/steamdb/global.js b/scripts/steamdb/global.js index b7f8f18f..ccc99786 100644 --- a/scripts/steamdb/global.js +++ b/scripts/steamdb/global.js @@ -60,26 +60,40 @@ GetOption( { 'steamdb-highlight': true }, ( items ) => contentScriptQuery: 'FetchSteamUserData', }, ( response ) => { - if( response.error ) + console.log( document.readyState ); + + const OnPageLoaded = () => { - WriteLog( 'Failed to load userdata', response.error ); + if( response.error ) + { + WriteLog( 'Failed to load userdata', response.error ); - window.postMessage( { - version: EXTENSION_INTEROP_VERSION, - type: 'steamdb:extension-error', - error: `Failed to load your games. ${response.error}`, - }, GetHomepage() ); - } + window.postMessage( { + version: EXTENSION_INTEROP_VERSION, + type: 'steamdb:extension-error', + error: `Failed to load your games. ${response.error}`, + }, GetHomepage() ); + } - if( response.data ) - { - window.postMessage( { - version: EXTENSION_INTEROP_VERSION, - type: 'steamdb:extension-loaded', - data: response.data, - }, GetHomepage() ); + if( response.data ) + { + window.postMessage( { + version: EXTENSION_INTEROP_VERSION, + type: 'steamdb:extension-loaded', + data: response.data, + }, GetHomepage() ); - WriteLog( 'Userdata loaded', `Packages: ${response.data.rgOwnedPackages.length}` ); + WriteLog( 'Userdata loaded', `Packages: ${response.data.rgOwnedPackages.length}` ); + } + }; + + if( document.readyState === 'loading' ) + { + document.addEventListener( 'DOMContentLoaded', OnPageLoaded, { once: true } ); + } + else + { + OnPageLoaded(); } } ); } );