palapala_pdf 0.1.7 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/chrome-headless-server +11 -0
- data/examples/performance_benchmark.rb +6 -7
- data/lib/palapala/chrome_process.rb +48 -7
- data/lib/palapala/version.rb +1 -1
- data/lib/palapala.rb +7 -1
- data/palapala_pdf.gemspec +2 -2
- metadata +4 -4
- data/exe/chrome-headless-server.sh +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9359afef10584362d61be46353495ae97d4ee17a380912fac9ede823fc9d41b
|
4
|
+
data.tar.gz: 3c8fce8d86a1fa1e1a9394c7e46eb9fe487669f5d621eabf56cd0ae2c29dd33b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e026b00c0e48fc24a412314a51f612813c2ac6441bee5b48139999dc58ceeec0b9c2807edf0cd0c00cdffb99fbcd0bb6848b2fc53599ed8d51fe286ee3a77155
|
7
|
+
data.tar.gz: c759088c15ea39529b7cf9ccdb95dee9af3c7b8bb02c8bc3ab6aef73e59de4e93378cd12f85e7affd3c2c2a7c2c8a476449087d529ce98dfd1aa2806f9119adc
|
@@ -11,6 +11,7 @@ Palapala.setup do |config|
|
|
11
11
|
# config.headless_chrome_url = 'http://localhost:9222'
|
12
12
|
config.debug = debug
|
13
13
|
config.defaults.merge! scale: 0.75, format: :A4
|
14
|
+
config.chrome_headless_shell_version = 'canary'
|
14
15
|
end
|
15
16
|
|
16
17
|
# @param concurrency Number of concurrent threads
|
@@ -34,17 +35,15 @@ end
|
|
34
35
|
puts 'warmup'
|
35
36
|
benchmark(1, 10)
|
36
37
|
|
37
|
-
|
38
|
-
benchmark(1, 20)
|
38
|
+
# benchmark(1, 20)
|
39
39
|
benchmark(2, 10)
|
40
|
-
benchmark(4, 5)
|
40
|
+
# benchmark(4, 5)
|
41
41
|
# benchmark(5, 4)
|
42
42
|
# benchmark(20, 1)
|
43
43
|
|
44
|
-
|
45
|
-
benchmark(
|
46
|
-
benchmark(2, 320 / 2)
|
44
|
+
# benchmark(1, 320)
|
45
|
+
# benchmark(2, 320 / 2)
|
47
46
|
benchmark(4, 320 / 4)
|
48
|
-
benchmark(8, 320 / 8)
|
47
|
+
# benchmark(8, 320 / 8)
|
49
48
|
# benchmark(20, 2)
|
50
49
|
# benchmark(40, 1)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require "open3"
|
2
|
+
require "pathname"
|
3
|
+
|
1
4
|
module Palapala
|
2
5
|
# Manage the Chrome child process
|
3
6
|
module ChromeProcess
|
@@ -52,17 +55,55 @@ module Palapala
|
|
52
55
|
end
|
53
56
|
end
|
54
57
|
|
58
|
+
def self.npx_installed?
|
59
|
+
system("which npx > /dev/null 2>&1")
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.spawn_chrome_headless_server
|
63
|
+
# Run the command and capture the output
|
64
|
+
puts "Installing latest stable chrome-headless-shell..."
|
65
|
+
output, status = Open3.capture2("npx --yes @puppeteer/browsers install chrome-headless-shell@#{Palapala.chrome_headless_shell_version}")
|
66
|
+
|
67
|
+
if status.success?
|
68
|
+
# Extract the path from the output
|
69
|
+
result = output.lines.find { |line| line.include?("chrome-headless-shell@") }
|
70
|
+
if result.nil?
|
71
|
+
raise "Failed to install chrome-headless-shell"
|
72
|
+
end
|
73
|
+
_, chrome_path = result.split(" ", 2).map(&:strip)
|
74
|
+
|
75
|
+
# Directory you want the relative path from (current working directory)
|
76
|
+
base_dir = Dir.pwd
|
77
|
+
|
78
|
+
# Convert absolute path to relative path
|
79
|
+
relative_path = Pathname.new(chrome_path).relative_path_from(Pathname.new(base_dir)).to_s
|
80
|
+
|
81
|
+
puts "Launching chrome-headless-shell at #{relative_path}" if Palapala.debug
|
82
|
+
# Display the version
|
83
|
+
system("#{chrome_path} --version") if Palapala.debug
|
84
|
+
# Launch chrome-headless-shell with the --remote-debugging-port parameter
|
85
|
+
if Palapala.debug
|
86
|
+
spawn(chrome_path, "--remote-debugging-port=9222", "--disable-gpu")
|
87
|
+
else
|
88
|
+
spawn(chrome_path, "--remote-debugging-port=9222", "--disable-gpu", out: "/dev/null", err: "/dev/null")
|
89
|
+
end
|
90
|
+
else
|
91
|
+
raise "Failed to install chrome-headless-shell"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
55
95
|
# Spawn a Chrome child process
|
56
96
|
def self.spawn_chrome
|
57
97
|
return if chrome_running?
|
58
98
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
99
|
+
if self.npx_installed?
|
100
|
+
@chrome_process_id = spawn_chrome_headless_server
|
101
|
+
else
|
102
|
+
params = [ "--headless", "--disable-gpu", "--remote-debugging-port=9222" ]
|
103
|
+
params.merge!(Palapala.chrome_params) if Palapala.chrome_params
|
104
|
+
# Spawn an existing chrome with the path and parameters
|
105
|
+
@chrome_process_id = Process.spawn(chrome_path, *params)
|
106
|
+
end
|
66
107
|
|
67
108
|
# Wait until the port is in use
|
68
109
|
sleep 0.1 until port_in_use?
|
data/lib/palapala/version.rb
CHANGED
data/lib/palapala.rb
CHANGED
@@ -21,10 +21,16 @@ module Palapala
|
|
21
21
|
|
22
22
|
# URL to the headless Chrome instance when using the remote renderer
|
23
23
|
attr_accessor :headless_chrome_url
|
24
|
-
end
|
25
24
|
|
25
|
+
# Chrome headless shell version to use
|
26
|
+
attr_accessor :chrome_headless_shell_version
|
27
|
+
end
|
28
|
+
puts "setting defaults on palapala"
|
26
29
|
self.debug = false
|
27
30
|
self.defaults = { displayHeaderFooter: true, encoding: :binary }
|
28
31
|
self.headless_chrome_path = nil
|
29
32
|
self.headless_chrome_url = "http://localhost:9222"
|
33
|
+
self.chrome_headless_shell_version = ENV.fetch("CHROME_HEADLESS_SHELL_VERSION", "stable")
|
30
34
|
end
|
35
|
+
|
36
|
+
puts "hoo"
|
data/palapala_pdf.gemspec
CHANGED
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
|
|
29
29
|
f.start_with?(*%w[bin/ test/ spec/ draft/ features/ .git appveyor Gemfile])
|
30
30
|
end
|
31
31
|
end
|
32
|
-
spec.bindir = '
|
33
|
-
spec.executables =
|
32
|
+
spec.bindir = 'bin'
|
33
|
+
spec.executables = [ 'chrome-headless-server' ]
|
34
34
|
spec.require_paths = [ 'lib' ]
|
35
35
|
|
36
36
|
# Uncomment to register a new dependency of your gem
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: palapala_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koen Handekyn
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
@@ -43,7 +43,7 @@ description: This gem uses faw web sockets to render HTML into a PDF using Chrom
|
|
43
43
|
email:
|
44
44
|
- github.com@handekyn.com
|
45
45
|
executables:
|
46
|
-
- chrome-headless-server
|
46
|
+
- chrome-headless-server
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
@@ -55,10 +55,10 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- assets/images/logo-variant2.webp
|
57
57
|
- assets/images/logo.webp
|
58
|
+
- bin/chrome-headless-server
|
58
59
|
- examples/headers_and_footers.rb
|
59
60
|
- examples/js_based_rendering.rb
|
60
61
|
- examples/performance_benchmark.rb
|
61
|
-
- exe/chrome-headless-server.sh
|
62
62
|
- lib/palapala.rb
|
63
63
|
- lib/palapala/chrome_process.rb
|
64
64
|
- lib/palapala/pdf.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# Run the command and capture the output
|
4
|
-
echo "Installing latest stable chrome-headless-shell..."
|
5
|
-
output=$(npx @puppeteer/browsers install chrome-headless-shell@stable)
|
6
|
-
|
7
|
-
# Extract the path from the output
|
8
|
-
chrome_path=$(echo "$output" | grep "chrome-headless-shell@" | awk '{print $2}')
|
9
|
-
|
10
|
-
# Directory you want the relative path from (current working directory)
|
11
|
-
base_dir=$(pwd)
|
12
|
-
|
13
|
-
# Convert absolute path to relative path using Node.js
|
14
|
-
relative_path=$(node -e "console.log(require('path').relative('$base_dir', '$chrome_path'))")
|
15
|
-
|
16
|
-
echo "Launching chrome-headless-shell at $relative_path"
|
17
|
-
echo $("$chrome_path" --version)
|
18
|
-
# Launch chrome-headless-shell with the --remote-debugging-port parameter
|
19
|
-
"$chrome_path" --remote-debugging-port=9222
|