I try to use prerender.io with a Meteor 1.5 App. I use the npm prerender-node package
var prerenderio = Npm.require('prerender-node') .set('prerenderToken', token)
.set('protocol', protocol)
.set('host', host);
// Feed it to middleware! (app.use)
WebApp.connectHandlers.use(prerenderio);
I seed log in prerender.io with code 200. Paged are cached but pages only contain the head and an empty body.
To make tests, I added the package meteorhacks:inject-initial and inserted lines in the body and it works fine.
I wonder if I have a problem with the router that is flowrouter.
I also place
<head>
<meta charset="utf-8">
<meta name="fragment" content="!">
ALL <meta ... >
<!-- a script -->
<scripts ... >
<!-- prerenderio -->
<script> console.log(Date()); window.prerenderReady = false; </script>
</head>
To test, I flushed the cache of prerender.io.
when I test https://www.toto.com?_escaped_fragment_=
I don't have any time in the client console. I see the new line on prerender.io
I did the same test into
https://www.bing.com/webmaster/diagnostics/seo/analyzer
Now let's see the new cache line content:
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 21 Jun 2017 20:16:33 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Cache-Control: no-cache
Content-Encoding: gzip
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/utils.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/before.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/zone.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/tracer.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/after.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/reporters.js?1498075872540"></script>
<link rel="stylesheet" type="text/css" class="__meteor-css__" href="/f6675d95a01ce3ac63036505eb1ace94a68b1bb7.css?meteor_css_resource=true">
<meta charset="utf-8">
<title>Toto</title>
...
<meta name="robots" content="index, follow">
...
<!-- http referrer links -->
<meta name="referrer" content="always">
<meta name="fragment" content="!">
<!-- No resize on mobiles -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> <!--320-->
<!-- a script -->
<script ... ></script>
<!-- prerenderio -->
<script> console.log(Date()); window.prerenderReady = false; </script>
</head>
<body>
<script type="text/javascript">__meteor_runtime_config__ = JSON.parse(decodeURIComponent("%7B%22meteorRelease%22%3A%22METEOR%401.5-beta.8%22%2C%22meteorEnv%22%3A%7B%22NODE_ENV%22%3A%22production%22%2C%22TEST_METADATA%22%3A%22%7B%7D%22%7D%2C%22PUBLIC_SETTINGS%22%3A%7B%22analyticsSettings%22%3A%7B%22autorun%22%3Afalse%2C%22Mixpanel%22%3A%7B%22token%22%3A%225fc6f49885cbf2ec8d80a15c0a310399%22%2C%22people%22%3Atrue%7D%2C%22Google%20Analytics%22%3A%7B%22trackingId%22%3A%22UA-60492530-2%22%7D%7D%2C%22ga%22%3A%7B%22account%22%3A%22UA-60492530-2%22%7D%7D%2C%22ROOT_URL%22%3A%22https%3A%2F%2Fwww.Toto.com%22%2C%22ROOT_URL_PATH_PREFIX%22%3A%22%22%2C%22appId%22%3A%221yyz6nr2dyysy1rxvng3%22%2C%22autoupdateVersion%22%3A%2237dc9ce25f5e0f5f3a2253bdcb3c80166a4e83d2%22%2C%22autoupdateVersionRefreshable%22%3A%2273bc2363ca210840ec3d6947a649e3388beca5c5%22%2C%22autoupdateVersionCordova%22%3A%224b9074136556412500d12284625a4f5d81ac3f3d%22%7D"));</script>
<script type="text/javascript" src="/fef4959b1bc37d5a9c2a1c09ddcb28fd7c374f10.js?meteor_js_resource=true"></script>
</body>
</html>
Here I gave the entire body content. I didn't remove any line.
Prerender user here. We had issues with Prerender not waiting until all scripts ran to completion and therefore the calculated dom is not yet fully rendered which sounds like what you're encountering. We solved this by using the prerender ready flag described in the prerender documentation copied here for convenience:
Put this in your HTML:
<script> window.prerenderReady = false; </script>
When we see window.prerenderReady set to false, we'll wait until it's set to true to save the HTML. Execute the following when your page will be ready (usually after ajax calls).
window.prerenderReady = true;
Related
I'm using Supabase CDN's for a project. When I call the createClient() function this error comes up:
createClient is not defined
I tried it with an older version of the CDN, with another browser and using the old method of SupabaseClient.createClient, but I got:
SupabaseClient is not defined
Is the CDN not working correctly or something else?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML</title>
<!-- Custom Styles -->
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>Nothing to see here...</p>
<!-- Project -->
<script src="https://cdn.jsdelivr.net/npm/#supabase/supabase-js#2"></script>
<script src="main.js"></script>
</body>
</html>
const SupabaseKey = // api here
const SupabaseUrl =// URL here
const options = {
db: {
schema: 'public',
},
auth: {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true
}
}
const supabase = createClient(SupabaseUrl, SupabaseKey, options)
I fixed it by adding an import statement in the JS file like this:
import createClient from 'https://cdn.jsdelivr.net/npm/#supabase/supabase-js/+esm'
The +esm at the end of the URL is from universal module and it now works.
I'm using HtmlAgilityPack v1.11.21 and since upgrading to .NET Core 3.1, I started to receive the following error while trying to load up a web page via URL: 'UTF-8, text/html' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. (Parameter 'name')
I found this post 'UTF8' is not a supported encoding name, but I'm not sure where or how I'm supposed to implement:
System.Text.EncodingProvider provider = System.Text.CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(provider);
I tried placing it before calling
var web = new HtmlWeb();
var doc = web.Load(urlToSearch);
But that didn't solve the issue.
This was working fine before upgrading to .NET Core 3.1, so I'm not sure where exactly I need to implement a fix.
Any ideas would be appreciated!
Thanks!
For those asking for the url, I'd rather not share that, but here's the heading:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://www.somesite.com/graphics/cdn/bootstrap-3.3.4-base-and-theme-min.2.css">
<!-- Optional theme -->
<link rel='stylesheet' type="text/css" media="screen" href="http://fonts.googleapis.com/css?family=Droid+Sans:400,700">
<link rel="stylesheet" href="http://www.somesite.com/graphics/cdn/somesite-responsive.css">
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="/apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon-precomposed" sizes="60x60" href="/apple-touch-icon-60x60.png" />
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="/apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="/apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="/apple-touch-icon-152x152.png" />
<link rel="icon" type="image/png" href="/favicon-196x196.png" sizes="196x196" />
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
<link rel="icon" type="image/png" href="/favicon-128.png" sizes="128x128" />
<meta name="application-name" content=" " />
<meta name="msapplication-TileColor" content="#FFFFFF" />
<meta name="msapplication-TileImage" content="/mstile-144x144.png" />
<meta name="msapplication-square70x70logo" content="/mstile-70x70.png" />
<meta name="msapplication-square150x150logo" content="/mstile-150x150.png" />
<meta name="msapplication-wide310x150logo" content="/mstile-310x150.png" />
<meta name="msapplication-square310x310logo" content="/mstile-310x310.png" />
<meta property="og:url" content="http://www.somesite.com/">
<meta property="og:type" content="website">
<meta property="og:title" content="site title">
<meta property="og:image" content="http://www.somesite.com/graphics/somesite_square_logo.png">
<meta property="og:description" content="description">
<title>site title</title>
</head>
<body>
</body>
</html>
There doesn't look like there's anything special there. Was hoping it was a .NET Core 3.1 thing...
As another measure, I've tried implementing the below but the response.Content.ReadAsStringAsync() comes back as empty.
using var httpClient = new HttpClient();
{
var response = await httpClient.GetAsync(urlToSearch);
if (response.IsSuccessStatusCode)
{
var html = await response.Content.ReadAsStringAsync();
var doc = new HtmlDocument();
doc.LoadHtml(html);
var photoUrl = doc.QuerySelector("div #headshot").ChildNodes[0].Attributes["src"].Value;
return new OkObjectResult(photoUrl);
}
}
It looks like it's not the issue with .NET Core 3.1, but with the URL you are trying to load.
.NET Core 3.1 has UTF-8 among defaults
.NET Core, on the other hand, supports only the following encodings:
[...]
UTF-8 (code page 65001), which is returned by the Encoding.UTF8 property.
[...]
I don't recall any place in HTTP Headers or in HTML where a string similar to
UTF-8, text/html
is expected.
In headers it looks like:
Content-Type: text/html;charset=utf-8
In HTML, like:
<meta charset="utf-8"/>
or
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
The page itself could show no sings of a problem in browsers, because they are quite forgiving. And your code before upgrade also could ignore the , text/html part for a ton of reasons. And the issue started to appear after upgrade... for another ton of reasons.
If you do not control the server, then you probably should load the page manually, then remove this error (", text/html") from the string and feed the result to HtmlAgilityPack
Update
Considering your update:
HTTP headers are also important. Even more. They take precedence over <meta>. Try
curl -v yourURL
Not sure about ReadAsStringAsync returning an empty string: maybe it's the same issue - wrong headers, or it may be an error in your code (as far as I know, ReadAsStringAsync doesn't really returns a string). You can try passing the HTML as static string
html = "<!DOCTYPE html>...";
doc.LoadHtml(html);
To isolate the initial issue.
As for ReadAsStringAsync you should check first if it succeeds reading other sites. I looked on the Internet... there are a lot of possibilities. Don't know what will work for you.
If the issue is with the headers. Then you can try this Is it possible to make HttpClient ignore invalid ETag header in response? or this https://stackoverflow.com/a/29426046/12610347 or this How to make HttpClient ignore Content-Length header or something else to your liking.
I'm using phpunit with the extension of selenium 2 (Selenium2TestCase), for checking an interface of my website.
So my test page contains this :
testDisplay()
{
...
file_put_contents('/home/toto/www/screenshots/before.html', $this->source());
sleep(5);
file_put_contents(/home/toto/www/screenshots/after.html', $this->source());
$this->assertContains('toto42', $this->source());
...
}
Then when I execute :
$> phpunit testSelenium.php
I have 2 html files of my page, before the sleep(5) and after :
before.html :
<META charset="utf-8"/>
<META content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<TITLE>Test</TITLE>
<LINK href="/css/style.css" rel="stylesheet"/>
<LINK href="/css/bootstrap.css" rel="stylesheet"/>
<SCRIPT src="/js/jquery-1.7.1.min.js" type="text/javascript"/>
</HEAD></HTML>
after.html :
<META charset="utf-8"/>
<META content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<TITLE>Test</TITLE>
<LINK href="/css/style.css" rel="stylesheet"/>
<LINK href="/css/bootstrap.css" rel="stylesheet"/>
<SCRIPT src="/js/jquery-1.7.1.min.js" type="text/javascript"/>
</HEAD>
<BODY>
...
toto42
...
</BODY>
I don't understand why I have to put a sleep(5) to entirely load my page, did someone have an idea ?
And an other question what is the equivalent of clickAtAndWait (of PHPUnit_Extensions_SeleniumTestCase) for the Selenium2TestCase ?
Thanks in advance
I found an answer.
I'm looking for an HTML element in my page with a timeout and if it does not appear I wait with the function implicitWait();
testDisplay()
{
...
//I use 25000 for the timeout but anything else works too it depends on your loading page
$this->timeouts()->implicitWait(25000);
$this->assertContains('toto42', $this->source());
...
}
Does H5BP assume that you will write your JavaScript and jQuery code so that it only executes when the window has fully loaded (using the onload listener)? The reason I ask is that H5BP locates the jQuery inclusion script tag at the bottom of the body tag as shown below. However, the script in which a cookie is being set will not work unless I move the jquery.min.js script element to the head element which precedes the body (and thus the execution of the cookie script). Thanks.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
</head>
<body>
<p>This is HTML5 Boilerplate.</p>
<!-- Cookie isn't set when jquery.min.js follows this element block -->
<script>
var test_profile = { browserWidth: $(window).width() };
document.cookie = "test_profile=" + JSON.stringify(test_profile);
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
</body>
</html>
That first <script> block depends on jQuery ($(window).width()), so it cannot be used before jQuery has been loaded.
Just move that cookie script after the other two <script> blocks:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<script>
var test_profile = { browserWidth: $(window).width() };
document.cookie = "test_profile=" + JSON.stringify(test_profile);
</script>
below is part of my head section in HTML. i found that the content of my page always load before the jquery.css such that the layout is so plain and return to the desired layout after 0.5 second loading time. What should I modify the code in order to avoid the plain content? is it related to the deviceready? in before, href is to the hyperlink, after that, i change it to a local file. i surprised that even a local file, it use 0.5 second to load it, instead of loading it instantly.
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" href="jquery.mobile-1.0a1.min.css" />
<script src="jquery-1.4.3.min.js"></script>
<script src="jquery.mobile-1.0a1.min.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
document.addEventListener("menubutton", showConfirm, false);
}
</head>
Try moving the line that loads Cordova-2.3.0.js below the lines that load your CSS. So something like:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" href="jquery.mobile-1.0a1.min.css" />
<script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
<script src="jquery-1.4.3.min.js"></script>
<script src="jquery.mobile-1.0a1.min.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
document.addEventListener("menubutton", showConfirm, false);
}
</head>
It works after i change jquery mobile and jquery to latest version............