angular-seo icon indicating copy to clipboard operation
angular-seo copied to clipboard

Prevent the angular-seo script from running when the client is not a bot

Open BeOleg opened this issue 11 years ago • 9 comments

Some non-modern browsers have an issue with the createEvent and dispatchEvent functions.

For instance IE8 throws a whole bunch of errors.

To fix this I suggest to implent a feature that prevents the script from running when the client is not a bot.

currently I am using the following setup to fix this:

    <script src="lib/angular-seo/angular-seo-mock.js"></script>
     <!--[if !IE]>
        <script src="lib/angular-seo/angular-seo.js"></script>
     <![endif]-->   

angular-seo-mock.js:

angular.module('seo', []).run(function($rootScope){
    $rootScope.htmlReady = function(){
        return false;
    }
});

BeOleg avatar Oct 30 '13 11:10 BeOleg

You know, I was thinking, maybe we can check for window.callPhantom, and if it does, call it directly, instead of going through events? What do you think?

That would need testing though.

steeve avatar Oct 30 '13 16:10 steeve

What kind of testing framework would you like to use?. I can get around to it today. I'll need you to provide me with some basic guidelines though, such as: -Preferable testing framework(Mocha, Karma or other, I head 'testangular' is great). -Testing Scenarios. -Short SRS for the changes that you think that I should do in the server and client parts of the package.

Regards, O.

On Wed, Oct 30, 2013 at 6:01 PM, Steeve Morin [email protected]:

You know, I was thinking, maybe we can check for window.callPhantom, and if it does, call it directly, instead of going through events? What do you think?

That would need testing though.

— Reply to this email directly or view it on GitHubhttps://github.com/steeve/angular-seo/issues/11#issuecomment-27403852 .

BeOleg avatar Oct 30 '13 16:10 BeOleg

Oh! I didn't mean a testing framework, I meant testing it does actually work :) I mean, if you want to implement proper testing through a framework, that's fine with me, but don't overdo it.

In the mean time, can you try a version without any events, only checking for window.callPhantom and calling it if it exists, and then check it does actually work.

Something like replacing

var evt = document.createEvent('Event');
evt.initEvent('__htmlReady__', true, true);
document.dispatchEvent(evt);

to

if (typeof window.callPhantom == 'function') { 
    window.callPhantom();
}

And check if it actually works.

steeve avatar Oct 30 '13 16:10 steeve

And of course remove all the event listening code from the server.

steeve avatar Oct 30 '13 16:10 steeve

ok, I'll give it a try right now

On Wed, Oct 30, 2013 at 6:13 PM, Steeve Morin [email protected]:

And of course remove all the even listening code from the server.

— Reply to this email directly or view it on GitHubhttps://github.com/steeve/angular-seo/issues/11#issuecomment-27405576 .

BeOleg avatar Oct 30 '13 16:10 BeOleg

I removed the 'onInitialized', an left the 'onCallback' event untouched. I shall test if it works right away.

On Wed, Oct 30, 2013 at 6:20 PM, Oleg Belausov [email protected] wrote:

ok, I'll give it a try right now

On Wed, Oct 30, 2013 at 6:13 PM, Steeve Morin [email protected]:

And of course remove all the even listening code from the server.

— Reply to this email directly or view it on GitHubhttps://github.com/steeve/angular-seo/issues/11#issuecomment-27405576 .

BeOleg avatar Oct 30 '13 16:10 BeOleg

Seem to work just fine, should I push it in a separate branch and open a pull request?

On Wed, Oct 30, 2013 at 6:26 PM, Oleg Belausov [email protected] wrote:

I removed the 'onInitialized', an left the 'onCallback' event untouched. I shall test if it works right away.

On Wed, Oct 30, 2013 at 6:20 PM, Oleg Belausov [email protected] wrote:

ok, I'll give it a try right now

On Wed, Oct 30, 2013 at 6:13 PM, Steeve Morin [email protected]:

And of course remove all the even listening code from the server.

— Reply to this email directly or view it on GitHubhttps://github.com/steeve/angular-seo/issues/11#issuecomment-27405576 .

BeOleg avatar Oct 30 '13 16:10 BeOleg

Yeah open a PR, I'll probably merge that once I get to review it.

Thank you for your time.

steeve avatar Oct 30 '13 16:10 steeve

when i hit url: http://example.com/?escaped_fragment= but only In https request time not working . https://example.com/?escaped_fragment=

that time page is not render. how can resolve this issue. please help

my .htacesss file RewriteEngine On RewriteCond %{HTTPS} !=on

RewriteRule ^(.)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Tried for SSR -Verishal

Options +FollowSymLinks RewriteCond %{REQUEST_URI} ^/$ RewriteCond %{QUERY_STRING} ^escaped_fragment=/?(.)$ #RewriteCond %{QUERY_STRING} escaped_fragment=/([^&]) RewriteRule ^/(.) http://example.com:9090/$1 [R,L] ProxyPassReverse / http://example.com:9090/ Options Indexes FollowSymLinks MultiViews

Production envirment url: phantomjs --disk-cache=no --ssl-protocol=TLSv1 --ignore-ssl-errors=true --web-security=false /opt/bitnami/apache-tomcat/staging/ROOT/js/angular-seo-server.js 9090 https://example..com/

verishal avatar Nov 02 '17 05:11 verishal