Search code examples
javascriptdebuggingremote-debuggingweinre

How to load WEINRE dynamically?


I do not want to include WEINRE script in head section and I would like to load it on demand (on button click). I tried:

$.getScript('http://path-to-weinre-script.js#anonymous')

After loading WEINRE script client starts to make calls to /ws/target/t-9X periodically but there is no active targets in WEINRE console. How can I force WEINRE initialization without adding it to head section?


Solution

  • I have found it myself. The right way to load WEINRE dynamically is:

    (function(e){e.setAttribute("src","http://ip:port/target/target-script-min.js#anonymous");document.getElementsByTagName("body")[0].appendChild(e);})(document.createElement("script"));void(0);