ComposableWeb / poolbase

Create your own pool of information and let machines do the work for you.
https://poolbase.fyi
2 stars 1 forks source link

feat(bext): render content script UI in iframe dynamically #7

Open pixelmord opened 4 years ago

pixelmord commented 4 years ago

May be helpful

// content-scipt.js

const i = document.createElement('iframe')
const b = document.createElement('button')
const p = document.getElementById('some-id')

b.innerHTML = 'Open'
b.addEventListener('click', (evt) => {
  evt.preventDefault()
  chrome.runtime.sendMessage({ open: true }, (response) => {
    i.src = response
    p.appendChild(i)
  })
})
p.appendChild(b)

This opens the extension in the DOM of the page the script is running on. You will also need to add the below to the manifest.

// manifest.json

....
"web_accessible_resources": [
  "popup.html"
]
....