jalali
jalali

Reputation: 5

A js event for js Chrome extension (work on every tab had loaded a page)

I need a js event that must be activated immediately an page loaded and run a function just in that tab. In Chrome browser platform.

Upvotes: 0

Views: 36

Answers (1)

gengns
gengns

Reputation: 1653

1) Define your extension in a JSON called manifest.json. Here you need to specify which tabs will execute your app, for example tabs that match https://css-tricks.com/*

manifest.json

{
  "manifest_version": 2,
  "name": "Your Extension Name",
  "version": "0.1",
  "content_scripts": [
    {
      "matches": ["https://css-tricks.com/*"],
      "js": ["index.js"]
    }
  ]
}

2) Write your app. Here after loading all resources you can add your function. I'm using console.time to check how long it takes.

index.js

console.time('time')

window.addEventListener('load', event => {
    console.log('All resources finished loading!')
    console.timeEnd('time')
})

Hope this help :)

Upvotes: 1

Related Questions