Skip to content

[WIP] Enable having multiple browser tabs with a single node js and (headless) chrome instance #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cc99323
update puppeteer
MichaelBuessemeyer Dec 1, 2021
af79b71
First steps to adapt to react inline browser
MichaelBuessemeyer Dec 2, 2021
94826a9
[WPI] add multiple tabs to node process
MichaelBuessemeyer Dec 12, 2021
7bd0a82
[WIP] add run.js changes for multiple tabs support
MichaelBuessemeyer Dec 16, 2021
fd65fc0
add prettier and eslint
MichaelBuessemeyer Dec 25, 2021
2579bd1
add node as env to eslint
MichaelBuessemeyer Dec 25, 2021
db8f3df
Merge branch 'main' of github.com:cmfcmf/MagicMouse into add-prettier
MichaelBuessemeyer Dec 25, 2021
9a4a5c8
[WIP] add tab functionallity to mmbrowser morph
MichaelBuessemeyer Jan 8, 2022
35bfffa
apply pr feedback:
MichaelBuessemeyer Jan 15, 2022
9b3c625
Finish first version of multi tab support
MichaelBuessemeyer Jan 16, 2022
69ecc6a
Re-add eslint-config-prettier, check formatting in GitHub Actions
cmfcmf Jan 17, 2022
acd061e
Merge branch 'cmfcmf:main' into add-prettier
MichaelBuessemeyer Jan 21, 2022
1b1b514
Add first working mutlti tab version for nodejs;
MichaelBuessemeyer Jan 22, 2022
cbc4f20
Merge branch 'add-prettier' of github.com:MichaelBuessemeyer/MagicMouse
MichaelBuessemeyer Jan 22, 2022
69c9009
Integrate nodejs stdout stuck fix
MichaelBuessemeyer Jan 22, 2022
feb6a88
Prettied package and some other stuff
MichaelBuessemeyer Jan 30, 2022
c88397f
Improve scrolling and resizing UX
MichaelBuessemeyer Feb 6, 2022
13cdbee
improve scrolling and resizing in nodejs part
MichaelBuessemeyer Feb 6, 2022
556e7c3
pretty code and try to clean up magic mouse upon squeak shutdown (doe…
MichaelBuessemeyer Mar 1, 2022
198e1a1
clean up code
MichaelBuessemeyer May 26, 2022
c0e1da8
Merge branch 'main' of github.com:cmfcmf/MagicMouse
MichaelBuessemeyer May 26, 2022
abd0c1a
clean up code
MichaelBuessemeyer May 26, 2022
4e03ccb
reenable instrumenting functionality in run.js
MichaelBuessemeyer May 26, 2022
4a7d489
Pretty smalltalk
MichaelBuessemeyer May 26, 2022
480719c
Fix auto closing tabs of killed browser instances
MichaelBuessemeyer May 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MagicMouse runs on all platforms that run Squeak and Chrome, but works best and
- Right-click on images and code to transform them into `Morph`s. I call those "Portals". Because portals are cool.
- Supercharged search bar:
- If you type something with at least one space, your search terms are googled.
- If you start your search with `!s `, your search terms are used to search https://squeak.org.
- If you start your search with `!s`, your search terms are used to search <https://squeak.org>.
- `CTRL+L` toggles fullscreen.
- Dropped texts are typed into form fields.
- _browseIt_ any URL to open it in a browser.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
accessing
parseImage: payload into: aMaybeUsedForm

| format png form |
format := payload unsignedCharAt: 2.
format = $r
ifTrue: [ | width height |
width := payload unsignedLongAt: 3.
height := payload unsignedLongAt: 7.
png := payload copyFrom: 11 to: payload size.
form := Form extent: width @ height depth: 32.
1 to: width * height - 1 do: [:index |
form bits
at: index
put: (png at: index * 4 + 3) asInteger << 0 + ((png at: index * 4 + 2) asInteger << 8) + ((png at: index * 4 + 1) asInteger << 16) + ((png at: index * 4 + 0) asInteger << 24)]]
ifFalse: [ | reader |
format caseOf: {
[$p] -> [
reader := PNGReadWriter on: (payload copyFrom: 3 to: payload size) readStream.
form := reader nextImage].
[$j] -> [
reader := MMFastJPEGReader on: (payload readStream
skip: 2;
yourself).
form := reader nextImage: aMaybeUsedForm]}].
^ form
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
abandon

self closeTab.
super abandon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ public
changeLocation: aUrl

location := aUrl.
self sendCommand: $l withBuffer: aUrl asByteArray
MMProcessWrapper getOSDependentSingleton
sendCommand: $l
withBuffer: aUrl asByteArray
for: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-> to chrome
closeTab

self tabId ifNotNil: [MMProcessWrapper getOSDependentSingleton closeTab: self tabId]
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
connecting
connect: aUrl

| path arguments |
process := MMProcessWrapper newForOS.
self class debugEnabled ifTrue: [process enableDebug].
arguments := {
aUrl.
viewportSize x.
viewportSize y.
self class runChromeHeadless ifTrue: ['headless'] ifFalse: ['windowed'].
self class chromeProfilePath}.
self class doNotUsePrebuiltBinary
ifTrue: [
self assertNodeScriptExists.
path := self class gitRepositoryPath, FileDirectory slash, 'run.js'.
process
startNodeScript: path
arguments: arguments
nodeArguments: (self class debugNodejs ifTrue: [{'--inspect'}] ifFalse: [{}])]
ifFalse: [
path := (FileDirectory default / MMPluginDownloader filenameForCurrentPlatform) fullName.
process startCommand: path withArguments: arguments].

location := aUrl.

imageUpdaterProcess := [
[ | length command payload |
length := process stdoutNextUint32.
payload := process stdoutNextBuffer: length.
command := payload unsignedCharAt: 1.
command caseOf: {
[$i] -> [self updateImage: payload].
[$h] -> [self handlePortal: payload].
[$l] -> [self locationUpdated: payload].
[$s] -> [self handleStructuredData: payload].
[$g] -> [self handleGitClone: payload].
[$f] -> [self handleFormFields: payload]}] repeat] fork
self tabId: (MMProcessWrapper getOSDependentSingleton
lauchNewPageAt: aUrl
withExtend: self viewportSize x @ self viewportSize y
for: self).
location := aUrl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ contentOfField: anId changedTo: text
replaceFrom: 5 + id byteSize + 4
to: 5 + id byteSize + 4 + content byteSize - 1
with: content asByteArray.
self sendCommand: $t withBuffer: bytes
MMProcessWrapper getOSDependentSingleton
sendCommand: $t
withBuffer: bytes
for: self
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
disconnecting
dispose

process ifNotNil: [:p |
p terminate.
process := nil].
self closeTab.
imageUpdaterProcess ifNotNil: [:p |
p terminate.
imageUpdaterProcess := nil]
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ droppedDomainObject: aDomainObject at: aPoint
bytes
signedLongAt: 1 put: aPoint x;
signedLongAt: 5 put: aPoint y.
self sendCommand: $f withBuffer: bytes
MMProcessWrapper getOSDependentSingleton
sendCommand: $f
withBuffer: bytes
for: self
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ droppedString: aString at: aPoint
bytes
signedLongAt: 1 put: aPoint x;
signedLongAt: 5 put: aPoint y.
self sendCommand: $s withBuffer: bytes, strBuffer
MMProcessWrapper getOSDependentSingleton
sendCommand: $s
withBuffer: bytes, strBuffer
for: self

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ initialize
"Mark the image as opaque. Although we render PNGs, the browser should never send us an image of the webpage that includes transparency."
self isOpaque: true.
self image: self class logo.
self portalMorphs: Dictionary new
self portalMorphs: Dictionary new.
self performedAutoResizing: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
isConnected

^ process notNil
^ self tabId notNil
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
events
mouseWheel: anEvent

self sendEvent: #mouseWheel withNumber: (anEvent isWheelUp ifTrue: [0] ifFalse: [1])
| naturalScrollingDelta |
naturalScrollingDelta := anEvent wheelDelta x @ anEvent wheelDelta y negated.
self sendEvent: #mouseWheel withSignedPoint: naturalScrollingDelta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
performedAutoResizing: aBoolean

performedAutoResizing := aBoolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
performedAutoResizing

^ performedAutoResizing

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-> to chrome
sendEvent: anEventType withBuffer: aBuffer

self process
stdinPutUint32: aBuffer size + 2;
stdinPutChar: $e;
stdinPutUint8: (self eventTypeCode: anEventType);
stdinPutBuffer: aBuffer asByteArray
MMProcessWrapper getOSDependentSingleton
sendEvent: (self eventTypeCode: anEventType)
withBuffer: aBuffer
for: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-> to chrome
sendEvent: anEventType withSignedPoint: aPoint

self sendEvent: anEventType withBuffer: ((ByteArray new: 8)
signedLongAt: 1 put: aPoint x asInteger;
signedLongAt: 5 put: aPoint y asInteger;
yourself)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
tabId: anObject

tabId := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
tabId

^ tabId
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
<- from chrome
updateImage: payload

| format png form |
format := payload unsignedCharAt: 2.
format = $r
ifTrue: [ | width height |
width := payload unsignedLongAt: 3.
height := payload unsignedLongAt: 7.
png := payload copyFrom: 11 to: payload size.
form := Form extent: width @ height depth: 32.
1 to: width * height - 1 do: [:index |
form bits
at: index
put: (png at: index * 4 + 3) asInteger << 0 + ((png at: index * 4 + 2) asInteger << 8) + ((png at: index * 4 + 1) asInteger << 16) + ((png at: index * 4 + 0) asInteger << 24)]]
ifFalse: [ | reader |
format caseOf: {
[$p] -> [
reader := PNGReadWriter on: (payload copyFrom: 3 to: payload size) readStream.
form := reader nextImage].
[$j] -> [
reader := MMFastJPEGReader on: (payload readStream
skip: 2;
yourself).
form := reader nextImage: self image]}].
| form |
form := self class parseImage: payload into: self image.
form extent > viewportSize ifTrue: ["We need to crop the incoming image if we don't run Chrome in headless mode
or if we just resized the window and Chrome still sends us a bigger image than now requested."
form := form contentsOfArea: (0 @ 0 extent: viewportSize)].
Expand Down
Loading