Skip to content

A tool loads content script and its dependencies to web execution environment.

Notifications You must be signed in to change notification settings

flyakite/deps.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

deps.js

Load JavaScript and its dependencies for content script.

In browser extension world, the content script did not execution environment with the JavaScript in the page. What if I need to read a global variable in the page?

We want to put our content scripts to the page, but some of the scripts have dependencies with scripts from browser extension which cause other dependancy loaders not working. So we create this for content script to load scripts with their dependencies.

Inspired by require.js

Usage

//set config
deps.config({
  paths: {
    'jsapi': 'http://example.com/_ah/channel/jsapi',
    'jquery': chrome.extension.getURL('jquery-1.10.2.min.js'),
    'gmail': chrome.extension.getURL('gmail.js'),
    'react': chrome.extension.getURL('react-with-addons.js'),
    'dashboard': chrome.extension.getURL('dashboard.js'),
    'main': chrome.extension.getURL('main.js')
    'app': chrome.extension.getURL('app.js')
  },
  shim: {
    'jquery': {
      'waitSeconds': 3,
      'retry': 1
    },
    'dashboard':{
      'deps': ['react', 'jquery'],
      'retry': 1
    },
    'main':{
      'deps': ['jsapi', 'jquery', 'gmail', 'dashboard']
    }
  },
  waitSeconds: 10, //seconds to wait for each script or timeout, optional, default 7
  retry: 2,  //retry times for each script, optional, default 0
  css:{
    'bootstrap': 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css',
    'style': 'style.css'
  }
});

//load script
deps.load('main');
deps.load(['app', 'main']);

About

A tool loads content script and its dependencies to web execution environment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published