Skip to content

Commit 337511f

Browse files
committed
fixed playback button
1 parent 0b7962f commit 337511f

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

src/app/components/App.jsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class App extends Component {
7171
// adds listener to the effects that are gonna be sent from
7272
// our edited useReducer from the 'react' library.
7373
chrome.runtime.onConnect.addListener((port) => {
74+
// if our port is already open with the extension script,
75+
// we don't want to change this.portToExtension no more. We want
76+
// to keep every instance of the App associated with the specific
77+
// extension script that can communicated with the injected timeTravel.
7478
if (port.name !== 'injected-app' || this.portToExtension) return;
7579

7680
this.portToExtension = port;
@@ -91,10 +95,9 @@ class App extends Component {
9195
const { searchField } = this.state;
9296
const newDataActionType = newData.action.type.toLowerCase();
9397

94-
// get the date everytime an action fires and add it to state
95-
9698
const eventTime = Date.now();
97-
99+
100+
// get the date everytime an action fires and add it to state
98101
if (newDataActionType.includes(searchField.toLowerCase())) {
99102
this.setState(state => ({
100103
data: [...state.data, newData],
@@ -167,11 +170,13 @@ class App extends Component {
167170
}
168171

169172
actionInPlay() {
170-
const { data, isPlayingIndex, isPlaying } = this.state;
173+
const { data, isPlayingIndex } = this.state;
171174

172175
setTimeout(() => {
173176
this.toTheFuture();
174-
if (isPlaying && isPlayingIndex + 1 < data.length - 1) {
177+
// We CANT deconstruct isPlaying because we want it to be the value
178+
// when this function gets executed - 1000s later.
179+
if (this.state.isPlaying && isPlayingIndex + 1 < data.length - 1) {
175180
this.actionInPlay();
176181
} else {
177182
this.setState({ isPlaying: false });
@@ -260,7 +265,7 @@ class App extends Component {
260265
if (isPlayingIndex === 0) return;
261266

262267
if (!this.portToExtension) return console.error('No connection on stored port.');
263-
console.log('Sending timetravel PAST to extension');
268+
264269
this.portToExtension.postMessage({
265270
type: 'TIMETRAVEL',
266271
direction: 'backwards',
@@ -279,7 +284,8 @@ class App extends Component {
279284

280285
resetApp() {
281286
if (this.justStartedRecording) {
282-
this.justStartedRecording = false;
287+
// hacky: some pages will fire update twice on the background script
288+
setTimeout(() => this.justStartedRecording = false, 50);
283289
return;
284290
}
285291

src/browser/chrome/background.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const interceptedURLs = {};
77

88
chrome.tabs.onUpdated.addListener((id, info, tab) => {
99
if (tab.status !== 'complete' || tab.url.startsWith('chrome')) return;
10-
10+
console.log('refresh completed on: ', tab.url);
1111
// active page action button and inject extension.js
1212
chrome.pageAction.show(tab.id);
1313
chrome.tabs.executeScript(null, {
@@ -24,7 +24,6 @@ chrome.tabs.onUpdated.addListener((id, info, tab) => {
2424
{ action: 'refresh_devtool', tabId: tab.id },
2525
'devtools',
2626
);
27-
2827
});
2928

3029
function handleRequest(request) {

src/browser/chrome/extension.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
port.onMessage.addListener((msg) => {
77
// This is where we get messages from the App component.
88
// We get an object { type: 'TIMETRAVEL', direction: 'forward' }
9-
console.log('Got msg to timetravel: ', msg);
109
window.postMessage(msg);
1110
});
1211

src/browser/chrome/scripts/parser.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,16 @@ function commitAllHostEffectsReplacement() {
107107
// method names
108108
const USEREDUCER = 'useReducer';
109109
const COMMITALLHOSTEFFECTS = 'commitAllHostEffects';
110+
110111
// library key inside of bundle
111112
const reactLibraryPath = './node_modules/react/cjs/react.development.js';
112113
const reactDOMLibraryPath = './node_modules/react-dom/cjs/react-dom.development.js';
114+
113115
// get replacer method
114116
let injectableUseReducer = esprima.parseScript(useReducerReplacement.toString());
115-
116-
let injectableCommitAllHostEffects = esprima.parseScript(commitAllHostEffectsReplacement.toString());
117+
let injectableCommitAllHostEffects = esprima.parseScript(
118+
commitAllHostEffectsReplacement.toString(),
119+
);
117120

118121
// traverse ast to find method and replace body with our node's body
119122
function traverseTree(replacementNode, functionName, ast) {
@@ -136,7 +139,7 @@ function traverseBundledTree(replacementNode, functionName, ast, library) {
136139
if (node.key && node.key.value === library) {
137140
if (node.value.body.body[1].type === 'ExpressionStatement') {
138141
if (node.value.body.body[1].expression.callee.name === 'eval') {
139-
// create new ast
142+
// create new ast
140143
const reactLib = esprima.parseScript(node.value.body.body[1].expression.arguments[0].value);
141144
estraverse.traverse(reactLib, {
142145
enter(libNode) {

0 commit comments

Comments
 (0)