I need to create a Chrome extension that automates some interactions with a web app written in Polymer.
I have this generated HTML:
<paper-input id="value-input" label="Value" no-label-float="" tabindex="0" aria-disabled="false">
<paper-input-container class="style-scope paper-input">
<template is="dom-if" class="style-scope paper-input-container"></template>
<div class="input-content style-scope paper-input-container">
<div class="label-and-input-container style-scope paper-input-container" id="labelAndInputContainer">
<label aria-hidden="true" slot="label" class="style-scope paper-input" for="input-2"
id="paper-input-label-2">Value</label>
<input is="iron-input" slot="input" class="input-element style-scope paper-input" autocomplete="off"
placeholder="" autocapitalize="none" autocorrect="off" aria-describedby=""
aria-labelledby="paper-input-label-2" tabindex="0" id="input-2">
</div>
</div>
<div class="underline style-scope paper-input-container">
<div class="unfocused-line style-scope paper-input-container"></div>
<div class="focused-line style-scope paper-input-container"></div>
</div>
<div class="add-on-content style-scope paper-input-container"></div>
</paper-input-container>
</paper-input>
This input is part of a larger (Polymer) form, for which the Submit button only gets enabled if something is written in the input.
Unfortunately, naively doing a document.querySelector('#input-2').value = 'something'
will not work.
The button remains disabled. In order for the button to get enabled I need to utilize the API provided by Polymer to the upgraded elements.
So for example document.querySelector('paper-input').updateValueAndPreserveCaret('something')
(which utilizes the Polymer element's updateValueAndPreserveCaret
method) will work. The button will get notified and will get enabled.
The problem
From inside my extension's content script, I don't seem to have access to any of the properties/methods that get applied to custom components by Polymer.
For example if I attempt to document.querySelector('paper-input').updateValueAndPreserveCaret('something')
from inside my content script, I will get an error that updateValueAndPreserveCaret
is undefined.
This is true not only for methods provided by Polymer, but also for properties as well (e.g. document.querySelector('paper-input').$
is undefined too)
Is this a case where I cannot access properties and functions because they were created in a different window
context?