Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BeOleg opened this issue Oct 30, 2013 · 9 comments
Open

Comments

@BeOleg
Copy link
Contributor

BeOleg commented Oct 30, 2013

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;
    }
});
@steeve
Copy link
Owner

steeve commented Oct 30, 2013

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.

@BeOleg
Copy link
Contributor Author

BeOleg commented Oct 30, 2013

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 notifications@github.comwrote:

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//issues/11#issuecomment-27403852
.

@steeve
Copy link
Owner

steeve commented Oct 30, 2013

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
Copy link
Owner

steeve commented Oct 30, 2013

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

@BeOleg
Copy link
Contributor Author

BeOleg commented Oct 30, 2013

ok, I'll give it a try right now

On Wed, Oct 30, 2013 at 6:13 PM, Steeve Morin notifications@github.comwrote:

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


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

@BeOleg
Copy link
Contributor Author

BeOleg commented Oct 30, 2013

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 hellgy@gmail.com wrote:

ok, I'll give it a try right now

On Wed, Oct 30, 2013 at 6:13 PM, Steeve Morin notifications@github.comwrote:

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


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

@BeOleg
Copy link
Contributor Author

BeOleg commented Oct 30, 2013

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 hellgy@gmail.com 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 hellgy@gmail.com wrote:

ok, I'll give it a try right now

On Wed, Oct 30, 2013 at 6:13 PM, Steeve Morin notifications@github.comwrote:

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


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

@steeve
Copy link
Owner

steeve commented Oct 30, 2013

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

Thank you for your time.

@verishal
Copy link

verishal commented Nov 2, 2017

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants