Search code examples
javascriptgoogle-chrome-extensionbrowser-extension

Get DOM values in browser extension


I want to read a value of DOM element. I am new to browser extensions. I came across codes which provided help in executing a code in browser context but how do I fetch a value and use in extension's context?

var value = document.getElementById('id1'); // Here document should be of browser context.

Solution

  • Try

    var value = document.getElementById('id1').value;
    

    // note the extra .value.

    You have to access the DOM from content scripts.