1
1
mirror of https://github.com/ariya/phantomjs.git synced 2024-09-11 12:55:33 +03:00

Give appropriate URL to evaluated JS files and to the main page.

This will enable remote debugger to correctly load and display available runtime scripts.
Modules will be sourced from `JAVASCRIPT_SOURCE_PLATFORM_URL` template.
Program scripts which includes main script and any script loaded using `phantom.injectJs()` will be sourced from `JAVASCRIPT_SOURCE_CODE_URL` template.

Issue: #12864
This commit is contained in:
Ivan Radulovic 2016-01-14 11:08:55 -05:00 committed by Vitaly Slobodin
parent 3e8e04e3d6
commit 0e32928ae1
4 changed files with 8 additions and 6 deletions

View File

@ -40,6 +40,9 @@
#define HTTP_HEADER_CONTENT_LENGTH "content-length"
#define HTTP_HEADER_CONTENT_TYPE "content-type"
#define JAVASCRIPT_SOURCE_PLATFORM_URL "phantomjs://platform/%1"
#define JAVASCRIPT_SOURCE_CODE_URL "phantomjs://code/%1"
#define JS_ELEMENT_CLICK "(function (el) { " \
"var ev = document.createEvent('MouseEvents');" \
"ev.initEvent(\"click\", true, true);" \

View File

@ -381,7 +381,7 @@ void Phantom::loadModule(const QString& moduleSource, const QString& filename)
"require.cache['" + filename + "'].exports," +
"require.cache['" + filename + "']" +
"));";
m_page->mainFrame()->evaluateJavaScript(scriptSource);
m_page->mainFrame()->evaluateJavaScript(scriptSource, QString(JAVASCRIPT_SOURCE_PLATFORM_URL).arg(QFileInfo(filename).fileName()));
}
bool Phantom::injectJs(const QString& jsFilePath)
@ -479,7 +479,7 @@ void Phantom::onInitialized()
// Bootstrap the PhantomJS scope
m_page->mainFrame()->evaluateJavaScript(
Utils::readResourceFileUtf8(":/bootstrap.js"),
QString("phantomjs://bootstrap.js")
QString(JAVASCRIPT_SOURCE_PLATFORM_URL).arg("bootstrap.js")
);
}

View File

@ -147,7 +147,7 @@ REPL::REPL(QWebFrame* webframe, Phantom* parent)
linenoiseSetCompletionCallback(REPL::offerCompletion);
// Inject REPL utility functions
m_webframe->evaluateJavaScript(Utils::readResourceFileUtf8(":/repl.js"), QString("phantomjs://repl.js"));
m_webframe->evaluateJavaScript(Utils::readResourceFileUtf8(":/repl.js"), QString(JAVASCRIPT_SOURCE_PLATFORM_URL).arg("repl.js"));
// Add self to JavaScript world
m_webframe->addToJavaScriptWindowObject("_repl", this);

View File

@ -132,8 +132,7 @@ bool injectJsInFrame(const QString& jsFilePath, const QString& jsFileLanguage, c
return false;
}
// Execute JS code in the context of the document
const QUrl jsFileUrl = QUrl::fromLocalFile(QDir::currentPath()).resolved(jsFilePath);
targetFrame->evaluateJavaScript(scriptBody, jsFileUrl);
targetFrame->evaluateJavaScript(scriptBody, QString(JAVASCRIPT_SOURCE_CODE_URL).arg(QFileInfo(scriptPath).fileName()));
return true;
}
@ -148,7 +147,7 @@ bool loadJSForDebug(const QString& jsFilePath, const QString& jsFileLanguage, co
QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc);
scriptBody = QString("function __run() {\n%1\n}").arg(scriptBody);
targetFrame->evaluateJavaScript(scriptBody);
targetFrame->evaluateJavaScript(scriptBody, QString(JAVASCRIPT_SOURCE_CODE_URL).arg(QFileInfo(scriptPath).fileName()));
if (autorun) {
targetFrame->evaluateJavaScript("__run()", QString());