Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
753b852
Merge pull request #2 from reactrewind/dev
victorvrv Mar 1, 2019
1027fd2
Merge pull request #3 from victorvrv/master
victorvrv Mar 1, 2019
fcb0c1e
commit to handle merges
victorvrv Mar 1, 2019
bbdf7d7
Minor change in how React app connect actions to the state and action…
victorvrv Mar 1, 2019
509c3dc
Delete devtools_bundle.js
victorvrv Mar 2, 2019
1bc9f2e
Delete devtools_bundle.js.map
victorvrv Mar 2, 2019
8537156
added doubly linked list data structure
victorvrv Mar 2, 2019
8afe649
Merge branch 'master' of https://github.com/victorvrv/react-rewind
victorvrv Mar 2, 2019
aecd748
Merge pull request #4 from reactrewind/dev
victorvrv Mar 2, 2019
6c07872
Solved merge conficts
victorvrv Mar 2, 2019
9a0dae3
Merge pull request #6 from reactrewind/dev
victorvrv Mar 2, 2019
d95fea0
Added buttons back and forth time travel functionality
victorvrv Mar 2, 2019
1f59e3b
Merge branch 'dev' of https://github.com/victorvrv/react-rewind
victorvrv Mar 2, 2019
43d9933
Merge branch 'victor-dev'
victorvrv Mar 2, 2019
0039064
Merge last PR with the current chrome dev tools version.
victorvrv Mar 2, 2019
7a0780f
removed console.log from extension
victorvrv Mar 2, 2019
86e2dbd
deleted console.log
victorvrv Mar 2, 2019
e4fea21
Merge pull request #7 from reactrewind/dev
victorvrv Mar 4, 2019
73e4455
Minor change to background, extension and inject_script. Commiting be…
victorvrv Mar 4, 2019
9eed7c1
merged parser pull
victorvrv Mar 4, 2019
81bc3a9
Merge pull request #8 from reactrewind/dev
victorvrv Mar 4, 2019
28e3349
Merge pull request #9 from reactrewind/dev
victorvrv Mar 4, 2019
49ecd68
commiting handle of merge conflicts before new pull
victorvrv Mar 4, 2019
85a6236
Merge branch 'dev' of https://github.com/victorvrv/react-rewind into …
victorvrv Mar 4, 2019
457d39a
Connecting parser and chrome dev tools. Code is full of console.logs.
victorvrv Mar 4, 2019
fec8eae
Merge pull request #10 from victorvrv/victor-dev
victorvrv Mar 4, 2019
d064c77
Merge pull request #11 from reactrewind/dev
victorvrv Mar 6, 2019
208fa48
Connected dev tools with page. Injected script working, parsing worki…
victorvrv Mar 6, 2019
c989af1
Merge branch 'dev' of https://github.com/victorvrv/react-rewind into …
victorvrv Mar 6, 2019
4d3b80e
fixed wrong type for expected Number on TimeSlider
victorvrv Mar 7, 2019
5930cfd
Created long lived port between App and background. This is gonna be …
victorvrv Mar 7, 2019
6bf6647
Merge pull request #13 from reactrewind/dev
victorvrv Mar 7, 2019
67d7b4b
merged last PR into local branch
victorvrv Mar 7, 2019
2ac155d
Added turn on button
victorvrv Mar 7, 2019
8387ced
Update App.jsx
victorvrv Mar 7, 2019
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
Binary file removed .DS_Store
Binary file not shown.
585 changes: 446 additions & 139 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
"babel-eslint": "^10.0.1",
"eslint": "^5.14.1",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-react": "^7.12.4"
"eslint-plugin-react": "^7.12.4",
"watchify": "^3.11.1"
},
"dependencies": {
"escodegen": "^1.11.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"esprima": "^4.0.1",
"estraverse": "^4.2.0",
"lodash": "^4.17.11",
"react": "^16.8.1",
"react-dom": "^16.8.1"
"lodash": "^4.17.11"
}
}
34 changes: 21 additions & 13 deletions src/app/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class App extends Component {
isPlayingIndex: 0,
};

this.port = null;
this.portToExtension = null;

this.addActionToView = this.addActionToView.bind(this);
this.toTheFuture = this.toTheFuture.bind(this);
this.toThePast = this.toThePast.bind(this);
Expand All @@ -59,15 +60,10 @@ class App extends Component {
}

componentDidMount() {
// *******************************************************
// need to impletement setState for filteredData to same value as data
// this.setState({ data, filteredData: data });
// *******************************************************

// adds listener to the effects that are gonna be sent from
// our edited useReducer from the 'react' library.
chrome.runtime.onConnect.addListener((portFromExtension) => {
this.port = portFromExtension;
this.portToExtension = portFromExtension;

portFromExtension.onMessage.addListener((msg) => {
const newData = {
Expand All @@ -76,11 +72,11 @@ class App extends Component {
id: this.state.data.length,
};
this.setState((state) => ({
data: [...state.data, newData]
data: [...state.data, newData],
filteredData: [...state.data, newData],
}));
});
});
}

// functionality to change 'play' button to 'stop'
setIsPlaying() {
Expand All @@ -103,6 +99,18 @@ class App extends Component {
this.setState(state => ({
isRecording: !state.isRecording,
}));

// we query the active window so we can send it to the background script
// so it knows on which URL to run our devtool.
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const { url } = tabs[0];

// backgroundPort is a variable made avaiable by the devtools.js
backgroundPort.postMessage({
turnOnDevtool: true,
url,
});
});
}

actionInPlay() {
Expand Down Expand Up @@ -170,17 +178,17 @@ class App extends Component {

// function to travel to the FUTURE
toTheFuture() {
if (!this.port) return console.error('No connection on stored port.');
this.port.postMessage({
if (!this.portToExtension) return console.error('No connection on stored port.');
this.portToExtension.postMessage({
type: 'TIMETRAVEL',
direction: 'forward',
});
}

// function to travel to the PAST
toThePast() {
if (!this.port) return console.error('No connection on stored port.');
this.port.postMessage({
if (!this.portToExtension) return console.error('No connection on stored port.');
this.portToExtension.postMessage({
type: 'TIMETRAVEL',
direction: 'backwards',
});
Expand Down
77 changes: 51 additions & 26 deletions src/browser/chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,58 @@ chrome.tabs.onUpdated.addListener((id, info, tab) => {
});
});

let reqIndex = 0;
const urlCache = {};
chrome.webRequest.onBeforeRequest.addListener(
(request) => {
if (request.type === 'script' && !request.url.startsWith('chrome')
&& request.frameId === 0) {
// TODO: adjust comment
// Else we need to check wether or not this contains the react
// library. If it does, we need to send the edit javascript to
// out content script, so it can inject into the page. If it doesnt,
// we need to send the url to our content script so that it can
// add it to the page <script src=URL> AND add it to our cache, so
// that when we intercept it, we dont block it.
const syncRequest = new XMLHttpRequest();
syncRequest.open('GET', request.url, false);
syncRequest.send(null);
console.log(`Status: ${syncRequest.status} - Size of response: ${syncRequest.responseText.length}`);

sendMessageToContent(parseAndGenerate(syncRequest.responseText));

return { redirectUrl: 'javascript:' };
}
},
{ urls: ['<all_urls>'] },
['blocking'],
);

let interceptedUrl = '';
function handleRequest(request) {
// TODO: filter the request from the webRequest call.
if (!interceptedUrl.startsWith(request.initiator)) return { cancel: false };

console.log('intercepting... ', request);
if (request.type === 'script' && !request.url.startsWith('chrome')
&& request.frameId === 0) {
// TODO: adjust comment
// Else we need to check wether or not this contains the react
// library. If it does, we need to send the edit javascript to
// out content script, so it can inject into the page. If it doesnt,
// we need to send the url to our content script so that it can
// add it to the page <script src=URL> AND add it to our cache, so
// that when we intercept it, we dont block it.
const syncRequest = new XMLHttpRequest();
syncRequest.open('GET', request.url, false);
syncRequest.send(null);
console.log(`Status: ${syncRequest.status} - Size of response: ${syncRequest.responseText.length}`);

sendMessageToContent(parseAndGenerate(syncRequest.responseText));

return { redirectUrl: 'javascript:' };
}
}

// The App on the devtools panel start a connection so that it can
// tell us when to start intercepting the script requests.
chrome.runtime.onConnect.addListener((port) => {
port.onMessage.addListener((msg) => {
if (!msg.turnOnDevtool) return;
interceptedUrl = msg.url;
addScriptInterception();

// after activating our interception script, we refresh the active tab
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.update(tabs[0].id, { url: tabs[0].url });
});
});
});

function addScriptInterception() {
chrome.webRequest.onBeforeRequest.removeListener(handleRequest);
chrome.webRequest.onBeforeRequest.addListener(
handleRequest,
{ urls: ['<all_urls>'] },
['blocking'],
);
}

let reqIndex = 0;
function sendMessageToContent(codeString) {
const index = reqIndex++;
console.log(`Sending request ${index}.`);
Expand Down
11 changes: 10 additions & 1 deletion src/browser/chrome/devtools.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
chrome.devtools.panels.create('React Rewind', null, 'devtools.html');
chrome.devtools.panels.create('React Rewind',
null,
'devtools.html',
(extensionPanel) => {
const port = chrome.runtime.connect({ name: 'devtools' });
port.onMessage.addListener(() => {});
extensionPanel.onShown.addListener((panelWindow) => {
panelWindow.backgroundPort = port;
});
});
31 changes: 31 additions & 0 deletions src/browser/chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "React Rewind",
"version": "1.0",
"description": "Time travel",
"manifest_version": 2,
"page_action": {
"default_popup": "page_action.html"
},
"background": {
"scripts": ["devtools_bundle/bg_bundle.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["scripts/inject_script_tags.js"],
"run_at":"document_start"
}
],
"permissions": [
"<all_urls>",
"tabs",
"storage",
"webRequest",
"webRequestBlocking"
],
"web_accessible_resources": [
"scripts/linked_list.js",
"scripts/time_travel.js"
],
"devtools_page": "devtools.html"
}