Advertisement
Guest User

phantomstuff

a guest
Jul 25th, 2012
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var rawHTML = '<html>'
  2.             + '<head>'
  3.             + '</head>'
  4.             + '<body>'
  5.             +   '<script>'
  6.             +       'var connect = function() {'
  7.             +           'var client = new WebSocket("ws://localhost:11131");'
  8.             +           'client.onmessage = function(msg) {'
  9.             +               'var data = JSON.parse(msg.data);'
  10.                 // (1) do your parsing here by loading the URL in an iframe
  11.                 // once you are done, just send the result back via websocket.
  12.                 // (2) for the downloads, you can again send the cookies from the iframe
  13.                 // via postMessage API via websockets to your app.
  14.                 // (3) injecting variables into browser session should be a piece of cake
  15.                 // with this method. you just need to eval the stuff you have sent
  16.                 // via websockets.
  17.                 // (4) link traversing can be achieved by using the postMessage API again.
  18.             +               'client.send(JSON.stringify({'
  19.             +                   'data: data'
  20.             +               '}));'
  21.             +           '};'
  22.             +           'client.onclose = function(msg) {'
  23.             +               'console.log("Phantom Socket Closed! Reconnecting...");'
  24.             +               'connect();'
  25.             +           '};'
  26.             +       '};'
  27.             +       'connect();'
  28.             +   '</script>'
  29.             + '</body>'
  30.             + '</html>';
  31.  
  32. var page = require('webpage').create();
  33. page.localToRemoteUrlAccessEnabled = true;
  34. page.content = rawHTML;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement