title: Special/accented UTF-8 characters not recognised by PhantomJS
body: <p>I am currently having an issue with PhantomJS (version 2.1.1/Windows 7) not recognising UTF-8 characters. Prior to asking this question, I have found the following two articles useful to configuring the command prompt:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/17367755/6731332">PhantomJS arguments.js example UTF-8 not working</a></li>
  <li><a href="https://stackoverflow.com/a/388500/6731332">Unicode characters in Windows command line - how?</a></li>
  </ul>
  
  <p>As suggested by the second article, I used the command</p>
  
  <pre><code>chcp 65001
  </code></pre>
  
  <p>to change the code page to UTF-8. I then also set the command prompt's default font to Lucida console.</p>
  
  <p>To test this had worked, I created the following UTF-8 text file</p>
  
  <pre><code>---------------------------------------------------------
  San José
  Cañon City
  Przecław Lanckoroński
  François Gérard Hollande
  El Niño
  vis-à-vis
  ---------------------------------------------------------
  </code></pre>
  
  <p>and then ran the following command to demonstrate whether characters were being recognised and correctly displayed by the command prompt:</p>
  
  <pre><code>type utf8Test.txt
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9tpOF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9tpOF.png" alt="UTF-8 accented recognised and correctly displayed by the command prompt"></a></p>
  
  <p>After this worked, I turned my attention to PhantomJS. Following the instructions <a href="http://phantomjs.org/api/command-line.html" rel="nofollow noreferrer">here</a> i created the below settings json file to ensure that UTF-8 is the input and output character encoding (though this appears to be the default for according to the official documentation).</p>
  
  <pre><code>{
      "outputEncoding: "utf8",
      "scriptEncoding": "utf8"
  } 
  </code></pre>
  
  <p>I then ran the following JavaScript through PhantomJS using the aforementioned json settings file in the same command prompt window:</p>
  
  <pre><code>console.log("---------------------------------------------------------");
  
  console.log("San José");
  console.log("Cañon City");
  console.log("Przecław Lanckoroński");
  console.log("François Gérard Hollande");
  console.log("El Niño");
  console.log("vis-à-vis");
  
  console.log("---------------------------------------------------------");
  
  page = require('webpage').create();
  
  // Display the initial requested URL
  page.onResourceRequested = function(requestData, request) { 
      if(requestData.id === 1){
          console.log(requestData.url);
      }
  };
  
  // Display any initial requested URL response error
  page.onResourceError = function(resourceError) {
      if(resourceError.id === 1){
          console.log(resourceError.status + " : " + resourceError.statusText);
      }
  };
  
  page.open("https://en.wikipedia.org/wiki/San_José", function(status) {
      console.log("---------------------------------------------------------");
      phantom.exit();
  });
  </code></pre>
  
  <p>The output from running this script is shown below:</p>
  
  <p><a href="https://i.stack.imgur.com/E4v9j.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4v9j.jpg" alt="UTF-8 accented characters not displayed by PhantomJS"></a></p>
  
  <p>From this I can see that PhantomJS is not able to understand UTF-8 special characters, and furthermore it passes the "unknown" character to websites when provided with a special or accented character as below:</p>
  
  <pre><code>URL passed to PhantomJS:   
  https://en.wikipedia.org/wiki/San_José
  
  URL passed to remote host: 
  https://en.wikipedia.org/wiki/San_Jos%EF%BF%BD
  
  ----------------------------------------------
  
  %EF%BF%BD
  �
  
  instead of:
  
  %C3%A9
  é
  </code></pre>
  
  <p>This causes websites to respond with '400 : Bad Request' errors, and in the case of Wikipedia specifically, requesting the URL <a href="https://en.wikipedia.org/wiki/San_Jos%EF%BF%BD" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/San_Jos%EF%BF%BD</a> results in an error message of:</p>
  
  <blockquote>
    <p>Bad title - The requested page title contains an invalid UTF-8 sequence.</p>
  </blockquote>
  
  <p>So, with all this being said, does anyone know how to remedy this? There are many websites these days that use UTF-8 special/accented characters in their page urls, and it would be great if PhantomJS could be used to access them. </p>
  
  <p>I really appreciate any help or suggestions you can provide me with.</p>