11import * as utils from "../helpers/utils.js" ;
22import { allScripts } from "../index.js" ;
3- import "../content-scripts/ufs_global.js" ; // https://stackoverflow.com/a/62806068/23648002
4-
5- console . log ( UfsGlobal ) ;
3+ import { UfsGlobal } from "../content-scripts/ufs_global.js" ;
4+ // import "../content-scripts/ufs_global.js"; // https://stackoverflow.com/a/62806068/23648002
65
76const {
87 convertBlobToBase64,
@@ -14,6 +13,7 @@ const {
1413
1514const { ISOLATED , MAIN } = chrome . scripting . ExecutionWorld ;
1615const CACHED = {
16+ path : chrome . runtime . getURL ( "/scripts/" ) ,
1717 activeScriptIds : [ ] ,
1818 badges : { } ,
1919} ;
@@ -317,12 +317,13 @@ function listenNavigation() {
317317 try {
318318 const { tabId, frameId } = getDetailIds ( details ) ;
319319
320- // inject ufsglobal, contentscript, pagescript before run any scripts
321320 if ( eventChain === "onDocumentStart" ) {
322321 // clear badge cache on main frame
323322 if ( details . frameId === 0 ) CACHED . badges [ tabId ] = [ ] ;
323+ // inject ufs global
324324 injectUfsGlobal ( tabId , frameId ) ;
325325 }
326+
326327 runScriptsTab ( eventChain , MAIN , details ) ;
327328 runScriptsTab ( eventChain , ISOLATED , details ) ;
328329 runScriptsBackground ( eventChain , details ) ;
@@ -393,19 +394,26 @@ function injectUfsGlobal(tabId, frameId) {
393394 { files : [ "ufs_global.js" , "content_script.js" ] , world : ISOLATED } ,
394395 { files : [ "ufs_global.js" ] , world : MAIN } ,
395396 ] . forEach ( ( { files, world } ) => {
397+ let paths = files . map ( ( file ) => CACHED . path + "content-scripts/" + file ) ;
396398 utils . runScriptFile ( {
397- files : files . map ( ( file ) => "/scripts/content-scripts/" + file ) ,
398399 target : {
399400 tabId : tabId ,
400401 frameIds : [ frameId ] ,
401402 } ,
403+ func : ( paths , frameId ) => {
404+ paths . forEach ( ( path ) => {
405+ import ( path )
406+ . then ( ( ) => console . log ( "Ufs import SUCCESS" , frameId , path ) )
407+ . catch ( ( e ) => console . error ( "Ufs import FAILED" , frameId , e ) ) ;
408+ } ) ;
409+ } ,
410+ args : [ paths , frameId ] ,
402411 world : world ,
403412 } ) ;
404413 } ) ;
405414}
406415
407416function main ( ) {
408- // listen change active scripts
409417 cacheActiveScriptIds ( ) ;
410418 chrome . storage . onChanged . addListener ( ( changes , areaName ) => {
411419 // areaName = "local" / "sync" / "managed" / "session" ...
@@ -437,17 +445,6 @@ function main() {
437445 trackEvent ( "ufs-INSTALLED" ) ;
438446
439447 runScriptsBackground ( "runtime.onInstalled" , null , reason , true ) ;
440-
441- // inject ufsGlobal to all frames in all tabs
442- chrome . tabs . query ( { } , ( tabs ) => {
443- tabs . forEach ( ( tab ) => {
444- chrome . webNavigation . getAllFrames ( { tabId : tab . id } , ( frames ) => {
445- frames . forEach ( ( frame ) => {
446- injectUfsGlobal ( tab . id , frame . frameId ) ;
447- } ) ;
448- } ) ;
449- } ) ;
450- } ) ;
451448 } ) ;
452449
453450 chrome . action . setBadgeBackgroundColor ( { color : "#666" } ) ;
@@ -459,5 +456,3 @@ try {
459456} catch ( e ) {
460457 console . log ( "ERROR:" , e ) ;
461458}
462-
463- // https://developer.chrome.com/docs/extensions/develop/migrate/blocking-web-requests
0 commit comments