Browse Source

get tab content

tags/0.1.0
Sam 6 months ago
parent
commit
4c1f40eced
4 changed files with 21 additions and 0 deletions
  1. 7
    0
      src/content_script.js
  2. 6
    0
      src/manifest.json
  3. 7
    0
      src/popup/App.vue
  4. 1
    0
      webpack.config.js

+ 7
- 0
src/content_script.js View File

@@ -0,0 +1,7 @@
browser.runtime.onMessage.addListener(request => {
let response = ''
if (request.req === 'source-code') {
response = document.documentElement.innerHTML
}
return Promise.resolve({ content: response })
})

+ 6
- 0
src/manifest.json View File

@@ -16,6 +16,12 @@
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content_script.js"]
}
],
"permissions": ["*://*/", "activeTab", "storage"],
"options_ui": {
"page": "options/options.html",

+ 7
- 0
src/popup/App.vue View File

@@ -57,6 +57,7 @@ export default {
return {
authToken: null,
currentTab: null,
currentTabContent: null,
error: null,
loading: null,
message: null,
@@ -111,6 +112,12 @@ export default {
if (currentTab) {
this.currentTab = currentTab
this.updateError(null)
browser.tabs
.sendMessage(currentTab.id, { req: 'source-code' })
.then(response => {
this.currentTabContent = response.content
})
.catch(err => console.error(err))
}
},
updateError(error) {

+ 1
- 0
webpack.config.js View File

@@ -14,6 +14,7 @@ const config = {
background: './background.js',
'popup/popup': './popup/popup.js',
'options/options': './options/options.js',
content_script: './content_script.js',
},
output: {
path: __dirname + '/dist',

Loading…
Cancel
Save