Problem phantomjs with "body onload"


I have an error with phantomjs, I just want to get the page data, it works well with other pages.

When there is “” on the page, it tells me "Can’t find variable: loadData and points to the body onload line as an error, of course I can’t read the data and I get nothing .

loadData () is a (relevant) function that obtains the data.

Unmodifiable page code:

<title>Headless remote debugging</title>
const fetchjson = (url) => fetch(url).then(r => r.json());
function loadData() {
const getList = fetchjson("/json/list");
const getVersion = fetchjson('/json/version');
Promise.all([getList, getVersion]).then(parseResults);

function parseResults([listData, versionData]){
const version = versionData['WebKit-Version'];
const hash = version.match(/s(@(b[0-9a-f]{5,40}b)/)[1];
listData.forEach(item => appendItem(item, hash));

function appendItem(item, hash) {
let link;
if (item.devtoolsFrontendUrl) {
link = document.createElement("a");
var devtoolsFrontendUrl = item.devtoolsFrontendUrl.replace(//devtools//,'');
link.href =${hash}/${devtoolsFrontendUrl}&remoteFrontend=true;
link.title = item.title;
} else {
link = document.createElement("div");
link.title = "The tab already has active debugging session";

var text = document.createElement("div");
if (item.title)
text.textContent = item.title;
text.textContent = "(untitled tab)";
if (item.faviconUrl) = "background-image:url(" + item.faviconUrl + ")";

var p = document.createElement("p");

<body onload='loadData()'>
<div id='caption'>Inspectable WebContents</div>
<div id='items'></div>