$x("//a[contains(@href,'.jpg')]");
works as expected from the developer tools command prompt. But, when in an extension's content-script I get a '$x is not defined
'.
Why is this not available in a content-script or is there a special way of accessing it inside a content-script / Chrome extension?
I'm using Chrome 22 on Debian.
$x()
is not part of the run-time environment of a web page or content script. It is a tool that is part of the Command Line API for Chrome's DevTools.To use XPath in a content script, you need to do it the normal way, the DevTools convenient shortcut is not available.
Your code would look like this:
-- which is the kind of thing that
$x()
was doing for you, behind the scenes.While you are at it, consider switching to CSS selectors. Then the same functionality is:
-- which is much more palatable in my book.