1

I created a angularjs project with angular material.I added phantom js for seo to create html file for each page.My code,

var page = require('webpage').create();
                    page.open('http://website.com/', function (status) {
                        if (status !== 'success') {
                            console.log('Unable to access network');
                        } else {
                            var p = page.evaluate(function () {
                                return document.getElementsByTagName('html')[0].innerHTML
                            });
                            fs.write('home.html', page.content, 'w');
                        }
                        phantom.exit();
                    });
  page.onError = function (msg, trace) {
    console.log('msg', msg);
    trace.forEach(function(item) {
    console.log(' ', item.file, ':', item.line);
   });
}

After creation of html file, when I open the file in browser, the css is not getting applied and the design gets collapsed.Here is the screenshot of the issue.

https://i.stack.imgur.com/sCD0z.png

Could anyone suggest me what is the issue?Is it because I use angular material?

akila arasan
  • 737
  • 3
  • 11
  • 26
  • Check this answer for ideas: https://stackoverflow.com/a/38471938/2715393 – Vaviloff Jun 21 '17 at 05:57
  • @Vaviloff thanks for the suggestion, but those answers are for es6 feature support but mine is plain javascript – akila arasan Jun 21 '17 at 06:03
  • Doesn't Angular use ES6 as well? Anyway you should add `page.onerror` callback and see if there are any errors – Vaviloff Jun 21 '17 at 06:04
  • Also: are you sure that css and js are loaded when you open the resulting page in the browser? Could be relative paths to resources. – Vaviloff Jun 21 '17 at 06:06
  • @valviloff its an angularjs 1.x version project – akila arasan Jun 21 '17 at 06:12
  • Regardless of the version, the **standard practice** for debugging PhantomJS scripts is using page.onerror callback. If you it shows anything be sure to update the question with errors. – Vaviloff Jun 21 '17 at 08:50
  • Can you show the resulting HTML now? You could use pastebin.com or any similar site. – Vaviloff Jun 21 '17 at 10:24
  • @valviloff thanks for the relative path suggestion.The issue was that it was relative path to the resources – akila arasan Jun 21 '17 at 11:36

0 Answers0