send message to safari tab for autofill
This commit is contained in:
parent
ca5026429a
commit
0a056a3941
|
@ -91,7 +91,7 @@ export default class ContextMenusBackground {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.sendMessage(tab.id, {
|
BrowserApi.tabSendMessage(tab, {
|
||||||
command: 'collectPageDetails',
|
command: 'collectPageDetails',
|
||||||
tab: tab,
|
tab: tab,
|
||||||
sender: 'contextMenu',
|
sender: 'contextMenu',
|
||||||
|
|
|
@ -248,15 +248,11 @@ export default class MainBackground {
|
||||||
options.frameId = frameId;
|
options.frameId = frameId;
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.sendMessage(tab.id, {
|
BrowserApi.tabSendMessage(tab, {
|
||||||
command: 'collectPageDetails',
|
command: 'collectPageDetails',
|
||||||
tab: tab,
|
tab: tab,
|
||||||
sender: sender,
|
sender: sender,
|
||||||
}, options, () => {
|
}, options);
|
||||||
if (chrome.runtime.lastError) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLoginsToAdd(tab: any = null): Promise<any> {
|
async checkLoginsToAdd(tab: any = null): Promise<any> {
|
||||||
|
|
|
@ -81,19 +81,33 @@ class BrowserApi {
|
||||||
return BrowserApi.tabSendMessage(tab, obj);
|
return BrowserApi.tabSendMessage(tab, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static tabSendMessage(tab: any, obj: any): Promise<any> {
|
static tabSendMessage(tab: any, obj: any, options: any = null): Promise<any> {
|
||||||
if (!tab || !tab.id) {
|
if (!tab || !tab.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BrowserApi.isChromeApi) {
|
if (BrowserApi.isChromeApi) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
chrome.tabs.sendMessage(tab.id, obj, () => {
|
chrome.tabs.sendMessage(tab.id, obj, options, () => {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
// Some error happened
|
||||||
|
}
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (BrowserApi.isSafariApi) {
|
} else if (BrowserApi.isSafariApi) {
|
||||||
return Promise.resolve(); // TODO
|
const win = safari.application.activeBrowserWindow;
|
||||||
|
if (safari.application.browserWindows.indexOf(win) !== tab.windowId) {
|
||||||
|
return Promise.reject('Window not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (safari.application.activeBrowserWindow.tabs.length < tab.index + 1) {
|
||||||
|
return Promise.reject('Tab not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const t = safari.application.activeBrowserWindow.tabs[tab.index];
|
||||||
|
t.page.dispatchMessage('bitwarden', obj);
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
!(function () {
|
!(function () {
|
||||||
/*
|
/*
|
||||||
1Password Extension
|
1Password Extension
|
||||||
|
|
||||||
|
@ -994,6 +994,26 @@
|
||||||
End 1Password Extension
|
End 1Password Extension
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if ((typeof safari !== 'undefined')) {
|
||||||
|
safari.self.addEventListener('bitwarden', function (msgEvent) {
|
||||||
|
var msg = msgEvent.message;
|
||||||
|
if (msg.command === 'collectPageDetails') {
|
||||||
|
var pageDetails = collect(document);
|
||||||
|
var pageDetailsObj = JSON.parse(pageDetails);
|
||||||
|
safari.self.tab.dispatchMessage('bitwarden', {
|
||||||
|
command: 'collectPageDetailsResponse',
|
||||||
|
tab: msg.tab,
|
||||||
|
details: pageDetailsObj,
|
||||||
|
sender: msg.sender
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (msg.command === 'fillForm') {
|
||||||
|
fill(document, msg.fillScript);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
||||||
if (msg.command === 'collectPageDetails') {
|
if (msg.command === 'collectPageDetails') {
|
||||||
var pageDetails = collect(document);
|
var pageDetails = collect(document);
|
||||||
|
|
|
@ -7,6 +7,8 @@ import AutofillField from '../models/autofillField';
|
||||||
import AutofillPageDetails from '../models/autofillPageDetails';
|
import AutofillPageDetails from '../models/autofillPageDetails';
|
||||||
import AutofillScript from '../models/autofillScript';
|
import AutofillScript from '../models/autofillScript';
|
||||||
|
|
||||||
|
import { BrowserApi } from '../browser/browserApi';
|
||||||
|
|
||||||
import { UtilsService } from 'jslib/services';
|
import { UtilsService } from 'jslib/services';
|
||||||
|
|
||||||
import { AutofillService as AutofillServiceInterface } from './abstractions/autofill.service';
|
import { AutofillService as AutofillServiceInterface } from './abstractions/autofill.service';
|
||||||
|
@ -170,9 +172,8 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||||
this.cipherService.updateLastUsedDate(options.cipher.id);
|
this.cipherService.updateLastUsedDate(options.cipher.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.sendMessage(tab.id, {
|
BrowserApi.tabSendMessage(tab, {
|
||||||
command: 'fillForm',
|
command: 'fillForm',
|
||||||
// tslint:disable-next-line
|
|
||||||
fillScript: fillScript,
|
fillScript: fillScript,
|
||||||
}, { frameId: pd.frameId });
|
}, { frameId: pd.frameId });
|
||||||
|
|
||||||
|
@ -238,16 +239,13 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|
||||||
private getActiveTab(): Promise<any> {
|
private async getActiveTab(): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
const tab = await BrowserApi.getTabFromCurrentWindow();
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs: any[]) => {
|
if (!tab) {
|
||||||
if (tabs.length === 0) {
|
throw new Error('No tab found.');
|
||||||
reject('No tab found.');
|
}
|
||||||
} else {
|
|
||||||
resolve(tabs[0]);
|
return tab;
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateFillScript(pageDetails: AutofillPageDetails, options: any): AutofillScript {
|
private generateFillScript(pageDetails: AutofillPageDetails, options: any): AutofillScript {
|
||||||
|
|
Loading…
Reference in New Issue