From 034fc35235e73400273953bf9d717035de580269 Mon Sep 17 00:00:00 2001 From: divdavem Date: Mon, 24 Oct 2016 16:23:47 +0200 Subject: [PATCH] Removing calls to document.write to load a script (#148) Instead of generating script tags for plugins client-side, it is now done server side, because calls to document.write to load a script can be blocked on Chrome in some cases, as documented in the following document: https://developers.google.com/web/updates/2016/08/removing-document-write --- lib/test-server/client/plugins.js | 27 --------------------------- lib/test-server/client/slave.html | 2 +- lib/test-server/test-server.js | 5 +++++ lib/test-type/test-content.json | 1 + lib/test-type/testPage.html | 1 - 5 files changed, 7 insertions(+), 29 deletions(-) delete mode 100644 lib/test-server/client/plugins.js diff --git a/lib/test-server/client/plugins.js b/lib/test-server/client/plugins.js deleted file mode 100644 index a98c1a3..0000000 --- a/lib/test-server/client/plugins.js +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2015 Amadeus s.a.s. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -(function () { - var window = this; - - function fixedEncodeURI(str) { - return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']'); - } - - window.location.search.replace(/(?:\?|\&)plugin=([^&]*)/g, function (match, plugin) { - var url = decodeURIComponent(plugin); - window.document.write(''); - return ""; - }); -})(); diff --git a/lib/test-server/client/slave.html b/lib/test-server/client/slave.html index 23ab86c..c03cb93 100644 --- a/lib/test-server/client/slave.html +++ b/lib/test-server/client/slave.html @@ -23,7 +23,7 @@ - + <% _(query.plugin || []).castArray().forEach(function (plugin) {%><%}); %> diff --git a/lib/test-server/test-server.js b/lib/test-server/test-server.js index 72e534f..d3e895c 100644 --- a/lib/test-server/test-server.js +++ b/lib/test-server/test-server.js @@ -225,6 +225,11 @@ var TestServer = function (config, logger) { page: "/status.html", path: path.join(__dirname, "client", "status.html") })); + app.use('/__attester__', template.bind({ + data: this, + page: "/slave.html", + path: path.join(__dirname, "client", "slave.html") + })); app.use('/__attester__', serveStatic(__dirname + '/client')); app.use('/__attester__/json3', serveStatic(path.dirname(require.resolve("json3/lib/json3.js")))); app.use('/__attester__/js-polyfills', serveStatic(path.dirname(require.resolve("js-polyfills")))); diff --git a/lib/test-type/test-content.json b/lib/test-type/test-content.json index 0536392..d96254a 100644 --- a/lib/test-type/test-content.json +++ b/lib/test-type/test-content.json @@ -1,6 +1,7 @@ { "head-start": [ "<%= data.name %>", + "<% _(query.plugin || []).castArray().forEach(function (plugin) { %><% }); %>", "<% _.forEach(data.config.extraScripts.before, function (script) { %><% }); %>" ], "head-end": [ diff --git a/lib/test-type/testPage.html b/lib/test-type/testPage.html index a2d4d6e..6487dd2 100644 --- a/lib/test-type/testPage.html +++ b/lib/test-type/testPage.html @@ -5,7 +5,6 @@ - <%= head %>