Skip to content

Commit

Permalink
By default detect page loading end using navigationDeletage Fix #15
Browse files Browse the repository at this point in the history
Other algorithm could be chosen to detect page loading
If no page loaded, NoContent is thrown
  • Loading branch information
phimage committed Sep 6, 2016
1 parent c5342b2 commit 5bc4727
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Erik.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |s|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "Erik"
s.version = "1.1.0"
s.version = "1.1.1"
s.summary = "A headless browser written in Swift"
s.description = <<-DESC
Erik is an headless browser based on WebKit and HTML parser Kanna.
Expand Down
68 changes: 34 additions & 34 deletions Erik.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@
isa = PBXNativeTarget;
buildConfigurationList = C42828EB1BF9EDE1005EC7C3 /* Build configuration list for PBXNativeTarget "Erik" */;
buildPhases = (
BF088855B5DAF2A7EA705BA7 /* Check Pods Manifest.lock */,
BF088855B5DAF2A7EA705BA7 /* [CP] Check Pods Manifest.lock */,
C42828D21BF9EDE1005EC7C3 /* Sources */,
C42828D31BF9EDE1005EC7C3 /* Frameworks */,
C42828D41BF9EDE1005EC7C3 /* Headers */,
C42828D51BF9EDE1005EC7C3 /* Resources */,
73264931D890451C857818B9 /* Copy Pods Resources */,
73264931D890451C857818B9 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -259,12 +259,12 @@
isa = PBXNativeTarget;
buildConfigurationList = C42828EE1BF9EDE1005EC7C3 /* Build configuration list for PBXNativeTarget "ErikTests" */;
buildPhases = (
FBE78F4AB43A129B1FEC79DD /* Check Pods Manifest.lock */,
FBE78F4AB43A129B1FEC79DD /* [CP] Check Pods Manifest.lock */,
C42828DD1BF9EDE1005EC7C3 /* Sources */,
C42828DE1BF9EDE1005EC7C3 /* Frameworks */,
C42828DF1BF9EDE1005EC7C3 /* Resources */,
0FCD568CDAC88AC57710E176 /* Embed Pods Frameworks */,
62E60B9AE07D42A5E0ED97AE /* Copy Pods Resources */,
0FCD568CDAC88AC57710E176 /* [CP] Embed Pods Frameworks */,
62E60B9AE07D42A5E0ED97AE /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -280,12 +280,12 @@
isa = PBXNativeTarget;
buildConfigurationList = C43178841BFA3E1A00C04250 /* Build configuration list for PBXNativeTarget "ErikOSX" */;
buildPhases = (
EA074855D0C7C0EB242B62F3 /* Check Pods Manifest.lock */,
EA074855D0C7C0EB242B62F3 /* [CP] Check Pods Manifest.lock */,
C431787A1BFA3E1A00C04250 /* Sources */,
C431787B1BFA3E1A00C04250 /* Frameworks */,
C431787C1BFA3E1A00C04250 /* Headers */,
C431787D1BFA3E1A00C04250 /* Resources */,
DA257F49A8A64F396E1DB044 /* Copy Pods Resources */,
DA257F49A8A64F396E1DB044 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -300,12 +300,12 @@
isa = PBXNativeTarget;
buildConfigurationList = C4D50DEF1BFB58EE0053B624 /* Build configuration list for PBXNativeTarget "ErikOSXTests" */;
buildPhases = (
6A78CCAB86D8196708AB81E9 /* Check Pods Manifest.lock */,
6A78CCAB86D8196708AB81E9 /* [CP] Check Pods Manifest.lock */,
C4D50DE31BFB58EE0053B624 /* Sources */,
C4D50DE41BFB58EE0053B624 /* Frameworks */,
C4D50DE51BFB58EE0053B624 /* Resources */,
7138017D10AC0A7C8C7B29FF /* Embed Pods Frameworks */,
31AD1E205B85890FF10084EE /* Copy Pods Resources */,
7138017D10AC0A7C8C7B29FF /* [CP] Embed Pods Frameworks */,
31AD1E205B85890FF10084EE /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -395,154 +395,154 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0FCD568CDAC88AC57710E176 /* Embed Pods Frameworks */ = {
0FCD568CDAC88AC57710E176 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ErikTests/Pods-ErikTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
31AD1E205B85890FF10084EE /* Copy Pods Resources */ = {
31AD1E205B85890FF10084EE /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ErikOSXTests/Pods-ErikOSXTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
62E60B9AE07D42A5E0ED97AE /* Copy Pods Resources */ = {
62E60B9AE07D42A5E0ED97AE /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ErikTests/Pods-ErikTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
6A78CCAB86D8196708AB81E9 /* Check Pods Manifest.lock */ = {
6A78CCAB86D8196708AB81E9 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
7138017D10AC0A7C8C7B29FF /* Embed Pods Frameworks */ = {
7138017D10AC0A7C8C7B29FF /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ErikOSXTests/Pods-ErikOSXTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
73264931D890451C857818B9 /* Copy Pods Resources */ = {
73264931D890451C857818B9 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Erik/Pods-Erik-resources.sh\"\n";
showEnvVarsInLog = 0;
};
BF088855B5DAF2A7EA705BA7 /* Check Pods Manifest.lock */ = {
BF088855B5DAF2A7EA705BA7 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
DA257F49A8A64F396E1DB044 /* Copy Pods Resources */ = {
DA257F49A8A64F396E1DB044 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ErikOSX/Pods-ErikOSX-resources.sh\"\n";
showEnvVarsInLog = 0;
};
EA074855D0C7C0EB242B62F3 /* Check Pods Manifest.lock */ = {
EA074855D0C7C0EB242B62F3 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
FBE78F4AB43A129B1FEC79DD /* Check Pods Manifest.lock */ = {
FBE78F4AB43A129B1FEC79DD /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
10 changes: 8 additions & 2 deletions Erik/Erik.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum ErikError: ErrorType {
// Error provided by javascript
case JavaScriptError(message: String)
// A timeout occurs
case TimeOutError
case TimeOutError(time: NSTimeInterval)
// No content returned
case NoContent
// HTML is not parsable
Expand All @@ -46,6 +46,8 @@ public class Erik {
public var layoutEngine: LayoutEngine
public var htmlParser: HTMLParser

public var noContentPattern: String? = "<html><head></head><body></body></html>"

// Init the headless browser
public init(webView: WKWebView? = nil) {
if let view = webView {
Expand Down Expand Up @@ -133,6 +135,11 @@ public class Erik {
return
}

if let pattern = noContentPattern where html.rangeOfString(pattern, options: .RegularExpressionSearch) != nil {
completionHandler?(nil, ErikError.NoContent)
return
}

guard error == nil else {
completionHandler?(nil, error)
return
Expand Down Expand Up @@ -216,4 +223,3 @@ extension Erik {
}

}

Loading

0 comments on commit 5bc4727

Please sign in to comment.