palapala_pdf 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/chrome-headless-server +33 -0
- data/examples/performance_benchmark.rb +6 -7
- data/lib/palapala/chrome_process.rb +49 -7
- data/lib/palapala/version.rb +1 -1
- data/lib/palapala.rb +4 -0
- 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: 717b57250c5722d66ac2310681959abc3ef56498d026b797f13b293077369d2b
|
4
|
+
data.tar.gz: cef8fc4f830a237020cfa6379add09c40da64c818b1758261d560e5ed3482fdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a31ddde9c4617397ff1a1ae13a708dbe4e54085c5d85043bf149bc602b0d6ebc3c1d9ee87d6fa42077146a159b045e398d599c0d3819b64eaeb4e31081afb0dc
|
7
|
+
data.tar.gz: a064e6622c5eb1737a0baa43a56fff6fd896b69c850b2120a3441b214fd8165ade5988f8bc971a0ddb37a19c900631f6935337e2682a1b8071e5a8c33ecd167c
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
# Run the command and capture the output
|
7
|
+
puts "Installing latest stable chrome-headless-shell..."
|
8
|
+
output, status = Open3.capture2('npx --yes @puppeteer/browsers install chrome-headless-shell@stable')
|
9
|
+
|
10
|
+
if status.success?
|
11
|
+
# Extract the path from the output
|
12
|
+
result = output.lines.find { |line| line.include?("chrome-headless-shell@") }
|
13
|
+
if result.nil?
|
14
|
+
puts "Failed to install chrome-headless-shell"
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
_, chrome_path = result.split(' ', 2).map(&:strip)
|
18
|
+
|
19
|
+
# Directory you want the relative path from (current working directory)
|
20
|
+
base_dir = Dir.pwd
|
21
|
+
|
22
|
+
# Convert absolute path to relative path
|
23
|
+
relative_path = Pathname.new(chrome_path).relative_path_from(Pathname.new(base_dir)).to_s
|
24
|
+
|
25
|
+
puts "Launching chrome-headless-shell at #{relative_path}"
|
26
|
+
# Display the version
|
27
|
+
system("#{chrome_path} --version")
|
28
|
+
# Launch chrome-headless-shell with the --remote-debugging-port parameter
|
29
|
+
exec("#{chrome_path} --remote-debugging-port=9222")
|
30
|
+
else
|
31
|
+
puts "Failed to install chrome-headless-shell"
|
32
|
+
exit 1
|
33
|
+
end
|
@@ -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,56 @@ 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
|
+
puts "spawning with output"
|
87
|
+
spawn(chrome_path, "--remote-debugging-port=9222", "--disable-gpu")
|
88
|
+
else
|
89
|
+
spawn(chrome_path, "--remote-debugging-port=9222", "--disable-gpu", out: "/dev/null", err: "/dev/null")
|
90
|
+
end
|
91
|
+
else
|
92
|
+
raise "Failed to install chrome-headless-shell"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
55
96
|
# Spawn a Chrome child process
|
56
97
|
def self.spawn_chrome
|
57
98
|
return if chrome_running?
|
58
99
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
100
|
+
if self.npx_installed?
|
101
|
+
@chrome_process_id = spawn_chrome_headless_server
|
102
|
+
else
|
103
|
+
params = [ "--headless", "--disable-gpu", "--remote-debugging-port=9222" ]
|
104
|
+
params.merge!(Palapala.chrome_params) if Palapala.chrome_params
|
105
|
+
# Spawn an existing chrome with the path and parameters
|
106
|
+
@chrome_process_id = Process.spawn(chrome_path, *params)
|
107
|
+
end
|
66
108
|
|
67
109
|
# Wait until the port is in use
|
68
110
|
sleep 0.1 until port_in_use?
|
data/lib/palapala/version.rb
CHANGED
data/lib/palapala.rb
CHANGED
@@ -21,10 +21,14 @@ 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
|
+
|
25
|
+
# Chrome headless shell version to use
|
26
|
+
attr_accessor :chrome_headless_shell_version
|
24
27
|
end
|
25
28
|
|
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 = "stable"
|
30
34
|
end
|
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.8
|
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
|