AutoControl Control your browser your way Forum               Install now from theChrome Web Store

ACtl.import


Loads a Javascript module file as a module object. This is equivalent to Javascript's import function, but allows to import any local file or URL. ACtl.import(location) is identical to ACtl.getFile(location, 'module'). It exists for convenience. ACtl.import(fileLocation) fileLocation Type: string Either a URL, data URI, local path or UNC path pointing to a Javascript module file. It can be relative to the script's location (if there is one). It can also contain placeholders such as <desktop>, <documents> and others. Returns Type: Promise Resolves to: module object Returns immediately. The Promise will resolve with the module object. Throws Type: string Error description if fileLocation cannot be accessed.

Example

Given the following Javascript module:

	//C:/Projects/Teleporter/functions.js
	export function teleportTo(destination){
		alert('We are now in ' + destination) ;
	}
	

We can import that module into our own scope as follows:

	try{
		let myModule = await ACtl.import('C:/Projects/Teleporter/functions.js') ;
		//now the entire module is in the `myModule` object
		myModule.teleportTo('Mars') ;
	}catch( error ){
		alert( "Couldn't import functions.js. The error was: " + error ) ;
	}
	
Scripting API Script Isolation Asynchronicity Backgrnd Scripts GUI vs API ACtl.include ACtl.import ACtl.getFile ACtl.saveFile ACtl.saveURL ACtl.openURL ACtl.closeTab ACtl.runInTab ACtl.runInFrames ACtl.runInPageCtx ACtl.getTabInfo ACtl.getTabIds ACtl.TAB_ID ACtl.setTabState ACtl.captureTab ACtl.execAction ACtl.runCommand ACtl.getClipboard ACtl.setClipboard ACtl.expand ACtl.switchState ACtl.var ACtl.pubVar ACtl.on ACtl.off ACtl.sleep ACtl.STOP_CHAIN ACtl.STOP_FULL_SEQ