Check whether user has a Chrome extension installed

前端 未结 16 2333
一向
一向 2020-11-22 08:50

I am in the process of building a Chrome extension, and for the whole thing to work the way I would like it to, I need an external JavaScript script to be able to detect if

16条回答
  •  深忆病人
    2020-11-22 09:11

    Here is an other modern approach:

    const checkExtension = (id, src, callback) => {
        let e = new Image()
        e.src = 'chrome-extension://'+ id +'/'+ src
        e.onload = () => callback(1), e.onerror = () => callback(0)
    }
    
    // "src" must be included to "web_accessible_resources" in manifest.json
    checkExtension('gighmmpiobklfepjocnamgkkbiglidom', 'icons/icon24.png', (ok) => {
        console.log('AdBlock: %s', ok ? 'installed' : 'not installed')
    })
    checkExtension('bhlhnicpbhignbdhedgjhgdocnmhomnp', 'images/checkmark-icon.png', (ok) => {
        console.log('ColorZilla: %s', ok ? 'installed' : 'not installed')
    })
    

提交回复
热议问题