title: Sending A postMessage in puppeteer (Nodejs Library)
body: <p>I know how to receive postMessages ,but I am looking to send a postMessage request to a site</p>
  <p>Just a Format</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const puppeteer = require('puppeteer');
  const yargs = require('yargs');
  
  let command = yargs.argv._[0];
  
  (async() =&gt; {
      const browser = await puppeteer.launch();
      const page = await browser.newPage();
  
  
  function sendMessageToContentScriptByPostMessage(data)
  {
      window.postMessage({cmd: 'message', data: data}, '*');
  }
  
      await page.goto(command, {waitUntil: 'networkidle0'});
  
      await browser.close();
  
  
  })();</code></pre>
  </div>
  </div>
  </p>
  <p>So the user can do this, node postmessage.js <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a></p>