Problem with phantomjs

131 views
Skip to first unread message

pedro martin martin

unread,
Dec 24, 2019, 3:57:24 PM12/24/19
to phantomjs
Hi,

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

When I have "<body onload = 'loadData ()'>" 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:

<html>
<head>
<title>Headless remote debugging</title>
<style>
</style>
<script>
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.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;
else
text.textContent = "(untitled tab)";
if (item.faviconUrl)
text.style.cssText = "background-image:url(" + item.faviconUrl + ")";
link.appendChild(text);

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

document.getElementById("items").appendChild(p);
}
</script>
</head>
<body onload='loadData()'>
<div id='caption'>Inspectable WebContents</div>
<div id='items'></div>
</body>
</html>

Thanks.

Nicolas Dermine

unread,
Dec 25, 2019, 9:27:30 AM12/25/19
to phan...@googlegroups.com
Hi Pedro,

do your other pages use "modern" JavaScript?

I see that before the `loadData` function definition you have this line:

```js
const fetchjson = (url) => fetch(url).then(r => r.json());
```

last time I used phantomjs its JavaScript engine did not support ES6 syntax.

you may want to use another tool,
nico



--
You received this message because you are subscribed to the Google Groups "phantomjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phantomjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/phantomjs/3bf80775-4c20-4084-a5a3-d6d6d25a8b95%40googlegroups.com.

Léo Adam

unread,
Jul 16, 2023, 3:33:41 AM7/16/23
to phantomjs
  je viens par ce présent message témoigner de ce que m’a fait cette  dame après avoir été tombée suis cinq faux prêteurs qui m'ont plus ruiné .  En effet, cette dame m'ai été d'une aide précieuse suite la maladie de ma petite qui était atteintes de sclérose, elle m'a prêté 5000€ dans un bref délai. Elle  est une source et confiance et de dignité, je vous l'a conseille vivement pour vos besoins financiers. Voilà sont adresse mail : celinemarieceline@ outlook.com
Reply all
Reply to author
Forward
0 new messages