M
M
Marcuzy2014-01-20 09:43:44
JavaScript
Marcuzy, 2014-01-20 09:43:44

Reading "custom" properties of a dom element from content_script Chrome's Extentsion

Hello. I am developing an extension for Google Chrome. It was necessary to parse the pages of one site, specifically there is an element with a certain id, as I understand it, that some script of this site sets a non-standard property t_content for this element . I can access this property via chrome console:
document.getElementById('item_id').t_content;
The code prints a line to the console - what you need. I need to do the same in content_script, but only the typeof of this property is "undefined" there. I don't understand what's the matter. I tried to play with run_at in manifest.json, but it didn’t work, especially since the default value is just right. The element already exists at the time of the request, but the property does not. This property is set by the script, taking into account the possible delay, I used setTimeout, but many iterations of the timer with a delay of 500ms did not change anything - the same "undefined".
I tried to set other "own" properties for the same element in the console: the result is the same.
What could be the problem, maybe a bug, or I did not take into account something.
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marcuzy, 2014-01-20
@Marcuzy

The method with embedding the script works with a bang.

function _script_(){
  function _tc_(sel){ 
    return typeof sel != "undefined" && sel !=null ? sel.t_content : "no";
  }

  window.postMessage({ 
    type: "FROM_PAGE",
    type_of_wp: _tc_(document.querySelector(".team-0 .withTip.firearms")),
    rank : _tc_(document.querySelector(".team-0 .withTip.sp.g1eb8.ic12453f2.d3710")),
    clothes: _tc_(document.querySelector(".team-0 .withTip.armor-plating")),
    house:_tc_(document.querySelector(".register.statistics img.withTip"))
  }, "*");
}
var n = document.createElement('script');
n.innerHTML = _script_.toString() + " _script_();";

document.body.appendChild(n);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question