0

I have a webpage with css, font, js, etc - and these files call other files.

If I use netlog.js phantomjs example, all files are requested successfully (ie response is received).

If I use my company script (1000s of lines), I don't get a font file.

When I look at the netlog.js output, the missing file is the very last received but it is the 4th of 9 in terms of requested - meaning I can see it is requested 4th but the response (page.onResourceRecieved) doesn't start until after all others have returned.

When I look at the company script, the missing file is not requested at all - hence it is missing. How can someone mis-program phantomjs to ignore this file so that it isn't requested? I assume that is the bug I'm hunting for.

In case the HTML/CSS is the culprit somehow, I'm going to include it below.

I have an html page that includes a css file via style tag (partial tag below)

<style>@import url(//fast.fonts.net/t/1.css?apiType=ad&projectid=2731384a-7cac-11e5-9c62-005056a60fc6&fontids=32RbV4zvBY&campaignid=HKyhF7DchmY);@import url(//fonts.googleapis.com/css?family=Montserrat:700&text=%2C-ABCDEFGHILMNOPRSTUVWabcdefghilmnoprstuvw);

The 1.css? request is correctly processed and the the next import of css?family is also requested. That second imported url requests another file: http://fonts.gstatic.com/l/font?kit=IQHow_FEYlDC4Gzy_m8fcqJ_SlhcvGEAn8FM2hC_Gzi8FMKbpN1MIaqg2HOsKpgsB-MyxXR1frCnhD4ZhVnHAATo_LDfaGo7fRovcW5LQvM&skey=11a939c399e8c9fe&v=v7

The netlog.js picks up the fonts.gstatic.com request - even if it doesn't come back until after everything else. The company script doesn't figure out it needs to request fonts.gstatic.com.

Netlog is very basic - it doesn't mess with timing, headers, or events. I think the company script is doing something to stop the request for fonts.gstatic.com once it is discovered by phantom via some setting or event but I don't know where to start.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
DFBerry
  • 1,818
  • 1
  • 19
  • 37
  • I think this is the issue http://stackoverflow.com/questions/23404658/how-can-i-use-google-web-fonts-with-phantomjs – DFBerry Sep 08 '16 at 16:21
  • Which PhantomJS version do you use? Please register to the `onConsoleMessage`, `onError`, `onResourceError`, `onResourceTimeout` events ([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file-1_phantomerrors-js)). Maybe there are errors. – Artjom B. Sep 08 '16 at 18:10
  • No errors but this is a good suggestion for anyone who isn't already listening to these events. I'm using 2.1.1 and it does set a custom user agent. When I comment out setting of the user agent, it works as expected and as netlog works - so I'm pretty sure it is the custom user agent issue. – DFBerry Sep 08 '16 at 19:07
  • Google sites behave differently depending on the browser which can be detected through the user agent string. If the user agent string signals to a Google server that the browser is able to use some kind of feature that is not implemented in PhantomJS, of course this will break your script. – Artjom B. Sep 08 '16 at 19:20

0 Answers0